1Subject: restrict value range passed to isprint function 2 3According to C standards isprint argument shall be representable as an 4unsigned char or be equal to EOF, otherwise the behaviour is undefined. 5 6Passing arbitrary ints leads to segfault in nm program from elfutils. 7 8Restrict isprint argument range to values representable by unsigned char. 9 10Signed-off-by: Max Filippov <jcmvbkbc@gmail.com> 11 12Taken from buildroot 13 14Upstream-Status: Pending 15Signed-off-by: Khem Raj <raj.khem@gmail.com> 16 17--- 18Index: 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 39Index: 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 52