argp-standalone: restrict value range passed to isprint function
PATCH 1/1 argp-standalone: restrict value range passed to isprint function
According to C standards isprint argument shall be representable as an unsigned char or be equal to EOF, otherwise the behaviour is undefined.
Passing arbitrary ints leads to segfault in nm program from elfutils.
Restrict isprint argument range to values representable by unsigned char.
--- package/argp-standalone/0002-isprint.patch | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 package/argp-standalone/0002-isprint.patch
package/argp-standalone/0002-isprint.patch new file +35 -0
@@ -0,0 +1,35 @@ +Subject: restrict value range passed to isprint function + +According to C standards isprint argument shall be representable as an +unsigned char or be equal to EOF, otherwise the behaviour is undefined. + +Passing arbitrary ints leads to segfault in nm program from elfutils. + +Restrict isprint argument range to values representable by unsigned char. + +Signed-off-by: Max Filippov <[email protected]> +--- +diff -bu argp-standalone-1.3/argp.h argp-standalone-1.3-/argp.h +--- argp-standalone-1.3/argp.h 2015-04-28 10:31:39.015319337 +0300 ++++ argp-standalone-1.3-/argp.h 2015-04-28 10:27:46.526770624 +0300 +@@ -577,7 +577,7 @@ + else + { + int __key = __opt->key; +- return __key > 0 && isprint (__key); ++ return __key > 0 && __key <= UCHAR_MAX && isprint (__key); + } + } + +diff -bu argp-standalone-1.3/argp-parse.c argp-standalone-1.3-/argp-parse.c +--- argp-standalone-1.3/argp-parse.c 2015-04-28 10:31:39.016319380 +0300 ++++ argp-standalone-1.3-/argp-parse.c 2015-04-28 10:27:21.810818130 +0300 +@@ -1292,7 +1292,7 @@ + int __key = __opt->key; + /* FIXME: whether or not a particular key implies a short option + * ought not to be locale dependent. */ +- return __key > 0 && isprint (__key); ++ return __key > 0 && __key <= UCHAR_MAX && isprint (__key); + } + } +
Signature · 1 line
1.8.1.4
Thomas Petazzoni
AppliedPATCH 1/1 argp-standalone: restrict value range passed to isprint function
Dear Max Filippov,
Quoted 5 lines · Max Filippov
According to C standards isprint argument shall be representable as an unsigned char or be equal to EOF, otherwise the behaviour is undefined.
Passing arbitrary ints leads to segfault in nm program from elfutils.
Quoted 7 lines
Restrict isprint argument range to values representable by unsigned char.
Signed-off-by Max Filippov <[email protected]>--- package/argp-standalone/0002-isprint.patch | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 package/argp-standalone/0002-isprint.patch
Applied, thanks. I've added a reference to the corresponding glibc commit.
Thanks,
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com