Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1 | Subject: restrict value range passed to isprint function |
| 2 | |
| 3 | According to C standards isprint argument shall be representable as an |
| 4 | unsigned char or be equal to EOF, otherwise the behaviour is undefined. |
| 5 | |
| 6 | Passing arbitrary ints leads to segfault in nm program from elfutils. |
| 7 | |
| 8 | Restrict isprint argument range to values representable by unsigned char. |
| 9 | |
| 10 | Signed-off-by: Max Filippov <jcmvbkbc@gmail.com> |
| 11 | |
| 12 | Taken from buildroot |
| 13 | |
| 14 | Upstream-Status: Pending |
| 15 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 16 | |
| 17 | --- |
| 18 | Index: b/argp.h |
| 19 | =================================================================== |
| 20 | --- a/argp.h |
| 21 | +++ b/argp.h |
| 22 | @@ -23,6 +23,7 @@ |
| 23 | |
| 24 | #include <stdio.h> |
| 25 | #include <ctype.h> |
| 26 | +#include <limits.h> |
| 27 | |
| 28 | #define __need_error_t |
| 29 | #include <errno.h> |
| 30 | @@ -577,7 +578,7 @@ |
| 31 | else |
| 32 | { |
| 33 | int __key = __opt->key; |
| 34 | - return __key > 0 && isprint (__key); |
| 35 | + return __key > 0 && __key <= UCHAR_MAX && isprint (__key); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | Index: b/argp-parse.c |
| 40 | =================================================================== |
| 41 | --- a/argp-parse.c |
| 42 | +++ b/argp-parse.c |
| 43 | @@ -1292,7 +1292,7 @@ |
| 44 | int __key = __opt->key; |
| 45 | /* FIXME: whether or not a particular key implies a short option |
| 46 | * ought not to be locale dependent. */ |
| 47 | - return __key > 0 && isprint (__key); |
| 48 | + return __key > 0 && __key <= UCHAR_MAX && isprint (__key); |
| 49 | } |
| 50 | } |
| 51 | |