bug-cpio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-cpio] [PATCH] Fix isprint call with invalid argument


From: Corinna Vinschen
Subject: [Bug-cpio] [PATCH] Fix isprint call with invalid argument
Date: Mon, 13 Jun 2005 19:21:46 +0200
User-agent: Mutt/1.4.2i

Hi,

the below patch fixes a problem in lib/argp.h, relative to cpio 2.6.

The inline function __option_is_short calls isprint() on the incoming
short option character opt->key.  opt->key is of type int and the
isprint function expects an int as parameter, so everything looks well.

The problem is that the incoming key value is potentially outside of
the range allowed by isprint.  According to SUSv3:

"The c argument is an int, the value of which the application shall
 ensure is a character representable as an unsigned char or equal to
 the value of the macro EOF. If the argument has any other value, the
 behavior is undefined."

So, since some of the values are in the range >= 256 (see src/main.c,
cpio_options), isprint is called with values for which the result is
undefined.  This potentially results in option array parse errors,
so happened in the Cygwin port of cpio.


Thanks for considering,
Corinna


        * lib/argp.h (__option_is_short): Don't call isprint with
        out-of-range character values.


--- lib/argp.h.ORIG     2005-06-13 19:06:54.160955600 +0200
+++ lib/argp.h  2005-06-13 19:01:28.147427500 +0200
@@ -579,7 +579,7 @@ __NTH (__option_is_short (__const struct
   else
     {
       int __key = __opt->key;
-      return __key > 0 && isprint (__key);
+      return __key > 0 && __key < 256 && isprint (__key);
     }
 }
 

-- 
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat, Inc.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]