On Sat, 10 Oct 2015, Michael McConville wrote:
> Theo de Raadt wrote:
> > > Some isfoo(char) usages crept back into ftp
> > 
> > Hmm.  I wonder how we can keep these errors out of base.
> > Having to re-audit all the time is painful.
> 
> FWIW, this is a perfect use case for Coccinelle. Below is what I dredged
> up in src/usr.sbin (diff not yet carefully audited, but apparently
> sane).

I've committed this (with line wrap):

> --- ldapd/syntax.c
> +++ /tmp/cocci-output-29625-30ee70-syntax.c
> @@ -142,7 +142,7 @@ syntax_is_printable_string(struct schema
>       char            *p;
>  
>       for (p = value; len > 0 && *p != '\0'; p++, len--) {
> -             if (!isalnum(*p) && strchr(special, *p) == NULL)
> +             if (!isalnum((unsigned char)*p) && strchr(special, *p) == NULL)


as well as this:

> --- tcpdump/print-ipsec.c
> +++ /tmp/cocci-output-17550-499a71-print-ipsec.c
> @@ -101,7 +101,7 @@ esp_init (char *espspec)
>               s[0] = espkey[2*i];
>               s[1] = espkey[2*i + 1];
>               s[2] = 0;
> -             if (!isxdigit(s[0]) || !isxdigit(s[1])) {
> +             if (!isxdigit((unsigned char)s[0]) || !isxdigit((unsigned 
> char)s[1])) {


For tcpdump/print-decnet.c, I think it's best to change the variable type, 
as putchar() expects an int ("EOF or unsigned char") like isprint():


--- tcpdump/print-decnet.c      21 Aug 2015 02:07:32 -0000      1.14
+++ tcpdump/print-decnet.c      11 Oct 2015 03:25:02 -0000
@@ -756,11 +756,11 @@ dnname_string(u_short dnaddr)
 static void
 pdata(u_char *dp, u_int maxlen)
 {
-       char c;
+       int c;
        u_int x = maxlen;
 
        while (x-- > 0) {
-           c = *dp++;
+           c = (unsigned char)*dp++;
            if (isprint(c))
                putchar(c);
            else


For tcpdump/smbutil.c...gaaaaaaahhhhhh.  Add the return of atoi() to a 
pointer and then skip all digits?  That has *FUN* results with negative 
numbers and numbers greater than the length of the buffer!  fdata1() needs 
to be hit repeatedly with a big stick until it stops assuming that no one 
makes errors.

Reply via email to