diff options
author | Andy Dougherty <doughera@lafayette.edu> | 2013-01-16 12:30:43 -0500 |
---|---|---|
committer | Andy Dougherty <doughera@lafayette.edu> | 2013-01-16 13:02:28 -0500 |
commit | 94e529cc4d56863d7272c254a29eda2b002a4335 (patch) | |
tree | 5340bac792edbd5cc36afaa971160e02fa951bbc /perlio.c | |
parent | 73758d77f195684a5288d4a5ba4f2717f414d685 (diff) | |
download | perl-94e529cc4d56863d7272c254a29eda2b002a4335.tar.gz |
Avoid wraparound when casting unsigned size_t to signed ssize_t.
Practically, this only affects a perl compiled with 64-bit IVs on a 32-bit
system. In that instance a value of count >= 2**31 would turn negative
when cast to (ssize_t).
Diffstat (limited to 'perlio.c')
-rw-r--r-- | perlio.c | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -2155,7 +2155,7 @@ PerlIOBase_read(pTHX_ PerlIO *f, void *vbuf, Size_t count) SSize_t avail = PerlIO_get_cnt(f); SSize_t take = 0; if (avail > 0) - take = ((SSize_t)count < avail) ? (SSize_t)count : avail; + take = (((SSize_t) count >= 0) && ((SSize_t)count < avail)) ? (SSize_t)count : avail; if (take > 0) { STDCHAR *ptr = PerlIO_get_ptr(f); Copy(ptr, buf, take, STDCHAR); @@ -4086,7 +4086,7 @@ PerlIOBuf_unread(pTHX_ PerlIO *f, const void *vbuf, Size_t count) */ b->posn -= b->bufsiz; } - if (avail > (SSize_t) count) { + if ((SSize_t) count >= 0 && avail > (SSize_t) count) { /* * If we have space for more than count, just move count */ @@ -4136,7 +4136,7 @@ PerlIOBuf_write(pTHX_ PerlIO *f, const void *vbuf, Size_t count) } while (count > 0) { SSize_t avail = b->bufsiz - (b->ptr - b->buf); - if ((SSize_t) count < avail) + if ((SSize_t) count >= 0 && (SSize_t) count < avail) avail = count; if (flushptr > buf && flushptr <= buf + avail) avail = flushptr - buf; @@ -4411,7 +4411,7 @@ PerlIOPending_read(pTHX_ PerlIO *f, void *vbuf, Size_t count) { SSize_t avail = PerlIO_get_cnt(f); SSize_t got = 0; - if ((SSize_t)count < avail) + if ((SSize_t) count >= 0 && (SSize_t)count < avail) avail = count; if (avail > 0) got = PerlIOBuf_read(aTHX_ f, vbuf, avail); |