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>
This commit is contained in:
parent
eb50193136
commit
28db26f691
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user