summaryrefslogtreecommitdiffstats
path: root/src/testlib/qtestcase.cpp
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@theqtcompany.com>2016-05-30 15:25:06 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2016-05-31 11:37:01 +0000
commit28db26f6917174d787bd4c6eadbecebc952d59dc (patch)
tree6b614045a72dc3976ed6760fe04a5f00c5d449f5 /src/testlib/qtestcase.cpp
parenteb50193136c7c73be864e3232d01e98ddc24e539 (diff)
qtestcase: Fix buffer over-run, '\0' appended beyond buffer end
Noticed by Coverity (CID 161673). If the file being read contains enough to fill the buffer, read() shall do that and return the nbytes it was passed; as this was the size of the buffer, subsequently writing a '\0' at this index in buffer is out of bounds. Fortunately, /proc/self/status is typically < 1k so fits well inside the 2k buffer. All the same, we can safely pass sizeof(buffer) - 1 as nbytes and *be sure* of not getting a buffer over-run. Change-Id: Ib620a330fbc94f0579c953737f7c4417ca449968 Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@theqtcompany.com>
Diffstat (limited to 'src/testlib/qtestcase.cpp')
-rw-r--r--src/testlib/qtestcase.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index 62649441db..eae490e278 100644
--- a/src/testlib/qtestcase.cpp
+++ b/src/testlib/qtestcase.cpp
@@ -2514,7 +2514,7 @@ static bool debuggerPresent()
if (fd == -1)
return false;
char buffer[2048];
- ssize_t size = read(fd, buffer, sizeof(buffer));
+ ssize_t size = read(fd, buffer, sizeof(buffer) - 1);
if (size == -1) {
close(fd);
return false;