diff options
author | Guido van Rossum <guido@python.org> | 1996-06-11 18:38:48 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1996-06-11 18:38:48 (GMT) |
commit | 8bac546e1150f213d27e5f0e0ecfaf0c826be83f (patch) | |
tree | 4490f8864ea1995d5729e505bdf97ff82fe82178 | |
parent | 65af28a0f46f3da32a849e45ea725db041376444 (diff) | |
download | cpython-8bac546e1150f213d27e5f0e0ecfaf0c826be83f.zip cpython-8bac546e1150f213d27e5f0e0ecfaf0c826be83f.tar.gz cpython-8bac546e1150f213d27e5f0e0ecfaf0c826be83f.tar.bz2 |
Avoid core dump in resizestring() on read() with 0 bytes.
-rw-r--r-- | Modules/posixmodule.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 338a40c..a4268dd 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; } |