summaryrefslogtreecommitdiff
path: root/perlio.c
diff options
context:
space:
mode:
authorAndy Dougherty <doughera@lafayette.edu>2013-01-16 12:30:43 -0500
committerAndy Dougherty <doughera@lafayette.edu>2013-01-16 13:02:28 -0500
commit94e529cc4d56863d7272c254a29eda2b002a4335 (patch)
tree5340bac792edbd5cc36afaa971160e02fa951bbc /perlio.c
parent73758d77f195684a5288d4a5ba4f2717f414d685 (diff)
downloadperl-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.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/perlio.c b/perlio.c
index 3e6e0a6c46..5de5e65cb3 100644
--- a/perlio.c
+++ b/perlio.c
@@ -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);