xref: /OK3568_Linux_fs/buildroot/package/argp-standalone/0002-isprint.patch (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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---
12Index: b/argp.h
13===================================================================
14--- a/argp.h
15+++ b/argp.h
16@@ -23,6 +23,7 @@
17
18 #include <stdio.h>
19 #include <ctype.h>
20+#include <limits.h>
21
22 #define __need_error_t
23 #include <errno.h>
24@@ -577,7 +578,7 @@
25   else
26     {
27       int __key = __opt->key;
28-      return __key > 0 && isprint (__key);
29+      return __key > 0 && __key <= UCHAR_MAX && isprint (__key);
30     }
31 }
32
33Index: b/argp-parse.c
34===================================================================
35--- a/argp-parse.c
36+++ b/argp-parse.c
37@@ -1292,7 +1292,7 @@
38       int __key = __opt->key;
39       /* FIXME: whether or not a particular key implies a short option
40        * ought not to be locale dependent. */
41-      return __key > 0 && isprint (__key);
42+      return __key > 0 && __key <= UCHAR_MAX && isprint (__key);
43     }
44 }
45
46