diff options
author | tom <> | 2005-05-01 19:39:02 +0000 |
---|---|---|
committer | tom <> | 2005-05-01 19:39:02 +0000 |
commit | f2208352d509aa0b6dc4dc9c4f5c42c77bbf5087 (patch) | |
tree | b14ed3be20e3986c0756c5726c76f78cc0a30a0c /src/lib | |
parent | b9eaa570507dab5c979060383d2003ccb5242f91 (diff) | |
download | openbsd-f2208352d509aa0b6dc4dc9c4f5c42c77bbf5087.tar.gz openbsd-f2208352d509aa0b6dc4dc9c4f5c42c77bbf5087.tar.bz2 openbsd-f2208352d509aa0b6dc4dc9c4f5c42c77bbf5087.zip |
Tidy up __strtosignal(): pass a buffer and length to its itoa() and
make sure we can't underrun this buffer. Also force NUL-termination
of this buffer, and ensure that large unsigned integers are printed
correctly.
Started by a diff from Dave Hines, openbsd (at) dph (dot) fluff (dot)
org; thanks.
with and ok otto@
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libc/string/__strsignal.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/lib/libc/string/__strsignal.c b/src/lib/libc/string/__strsignal.c index ebbf08d24a..09054a9517 100644 --- a/src/lib/libc/string/__strsignal.c +++ b/src/lib/libc/string/__strsignal.c | |||
@@ -28,7 +28,7 @@ | |||
28 | */ | 28 | */ |
29 | 29 | ||
30 | #if defined(LIBC_SCCS) && !defined(lint) | 30 | #if defined(LIBC_SCCS) && !defined(lint) |
31 | static char *rcsid = "$OpenBSD: __strsignal.c,v 1.9 2005/03/30 20:13:52 otto Exp $"; | 31 | static char *rcsid = "$OpenBSD: __strsignal.c,v 1.10 2005/05/01 19:39:02 tom Exp $"; |
32 | #endif /* LIBC_SCCS and not lint */ | 32 | #endif /* LIBC_SCCS and not lint */ |
33 | 33 | ||
34 | #ifdef NLS | 34 | #ifdef NLS |
@@ -45,17 +45,18 @@ static char *rcsid = "$OpenBSD: __strsignal.c,v 1.9 2005/03/30 20:13:52 otto Exp | |||
45 | #include <signal.h> | 45 | #include <signal.h> |
46 | #include <string.h> | 46 | #include <string.h> |
47 | 47 | ||
48 | static char *itoa(int num) | 48 | static char * |
49 | itoa(char *buffer, size_t buffer_size, unsigned int num) | ||
49 | { | 50 | { |
50 | static char buffer[11]; | 51 | char *p = buffer + buffer_size; |
51 | char *p; | ||
52 | 52 | ||
53 | p = buffer + 4; | 53 | *--p = '\0'; |
54 | while (num >= 10) { | 54 | while (num >= 10 && p > buffer + 1) { |
55 | *--p = (num % 10) + '0'; | 55 | *--p = (num % 10) + '0'; |
56 | num /= 10; | 56 | num /= 10; |
57 | } | 57 | } |
58 | *p = (num % 10) + '0'; | 58 | /* num < 10 || p == buffer + 1 */ |
59 | *--p = (num % 10) + '0'; | ||
59 | return p; | 60 | return p; |
60 | } | 61 | } |
61 | 62 | ||
@@ -79,12 +80,15 @@ __strsignal(int num, char *buf) | |||
79 | return((char *)sys_siglist[signum]); | 80 | return((char *)sys_siglist[signum]); |
80 | #endif | 81 | #endif |
81 | } else { | 82 | } else { |
83 | #define MAXINTDIGS 11 | ||
84 | char str[MAXINTDIGS]; | ||
85 | |||
82 | #ifdef NLS | 86 | #ifdef NLS |
83 | strlcpy(buf, catgets(catd, 1, 0xffff, UPREFIX), NL_TEXTMAX); | 87 | strlcpy(buf, catgets(catd, 1, 0xffff, UPREFIX), NL_TEXTMAX); |
84 | #else | 88 | #else |
85 | strlcpy(buf, UPREFIX, NL_TEXTMAX); | 89 | strlcpy(buf, UPREFIX, NL_TEXTMAX); |
86 | #endif | 90 | #endif |
87 | strlcat(buf, itoa(signum), NL_TEXTMAX); | 91 | strlcat(buf, itoa(str, sizeof(str), signum), NL_TEXTMAX); |
88 | } | 92 | } |
89 | 93 | ||
90 | #ifdef NLS | 94 | #ifdef NLS |