From: Guido van Rossum Date: Tue, 11 Jun 1996 18:38:48 +0000 (+0000) Subject: Avoid core dump in resizestring() on read() with 0 bytes. X-Git-Tag: v1.4b1~75 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8bac546e1150f213d27e5f0e0ecfaf0c826be83f;p=python Avoid core dump in resizestring() on read() with 0 bytes. --- diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 338a40c0d2..a4268dd9c5 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -1408,7 +1408,7 @@ posix_read(self, args) object *self; object *args; { - int fd, size; + int fd, size, n; object *buffer; if (!getargs(args, "(ii)", &fd, &size)) return NULL; @@ -1416,13 +1416,14 @@ posix_read(self, args) if (buffer == NULL) return NULL; BGN_SAVE - size = read(fd, getstringvalue(buffer), size); + n = read(fd, getstringvalue(buffer), size); END_SAVE - if (size < 0) { + if (n < 0) { DECREF(buffer); return posix_error(); } - resizestring(&buffer, size); + if (n != size) + resizestring(&buffer, n); return buffer; }