mirror of
https://github.com/python/cpython.git
synced 2025-11-17 01:25:57 +00:00
Avoid core dump in resizestring() on read() with 0 bytes.
This commit is contained in:
parent
65af28a0f4
commit
8bac546e11
1 changed files with 5 additions and 4 deletions
|
|
@ -1408,7 +1408,7 @@ posix_read(self, args)
|
||||||
object *self;
|
object *self;
|
||||||
object *args;
|
object *args;
|
||||||
{
|
{
|
||||||
int fd, size;
|
int fd, size, n;
|
||||||
object *buffer;
|
object *buffer;
|
||||||
if (!getargs(args, "(ii)", &fd, &size))
|
if (!getargs(args, "(ii)", &fd, &size))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -1416,13 +1416,14 @@ posix_read(self, args)
|
||||||
if (buffer == NULL)
|
if (buffer == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
BGN_SAVE
|
BGN_SAVE
|
||||||
size = read(fd, getstringvalue(buffer), size);
|
n = read(fd, getstringvalue(buffer), size);
|
||||||
END_SAVE
|
END_SAVE
|
||||||
if (size < 0) {
|
if (n < 0) {
|
||||||
DECREF(buffer);
|
DECREF(buffer);
|
||||||
return posix_error();
|
return posix_error();
|
||||||
}
|
}
|
||||||
resizestring(&buffer, size);
|
if (n != size)
|
||||||
|
resizestring(&buffer, n);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue