diff options
author | ache <ache@FreeBSD.org> | 1998-10-25 05:06:42 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 1998-10-25 05:06:42 +0000 |
commit | 2417749d837397cc925700187e8a6b26c72cd1f0 (patch) | |
tree | c13505744bbe3aee45de8638b717ccd2483d1583 /lib | |
parent | 9b46ae6518c317e8cd36404a03d21c73c905b516 (diff) | |
download | FreeBSD-src-2417749d837397cc925700187e8a6b26c72cd1f0.zip FreeBSD-src-2417749d837397cc925700187e8a6b26c72cd1f0.tar.gz |
fix unsigned overflow
PR: 8437
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/locale/ansi.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/libc/locale/ansi.c b/lib/libc/locale/ansi.c index a5a3362..c0871fe 100644 --- a/lib/libc/locale/ansi.c +++ b/lib/libc/locale/ansi.c @@ -127,22 +127,24 @@ wcstombs(s, pwcs, n) size_t n; { char *e; - int cnt = 0; + int cnt, nb; - if (!pwcs || !s) + if (!pwcs || !s || n > INT_MAX) return (-1); - while (n > 0) { + nb = n; + cnt = 0; + while (nb > 0) { if (*pwcs == 0) { *s = 0; break; } - if (!sputrune(*pwcs++, s, n, &e)) + if (!sputrune(*pwcs++, s, nb, &e)) return (-1); /* encoding error */ if (!e) /* too long */ return (cnt); cnt += e - s; - n -= e - s; + nb -= e - s; s = e; } return (cnt); |