RE: [PATCH for 3.8] iproute2: Add "ip netns pids" and "ip netns identify"
From: David Laight <hidden>
Date: 2013-01-21 09:54:35
quoted
quoted
quoted
quoted
quoted
quoted
+ if (!isdigit(ch))ch must be cast to unsigned char before passing to isdigit().isdigit is defined to take an int. A legacy of the implicit casts in the K&R C days. Casting to unsigned char would be pointless and silly.[...] It's not pointless. This is explained in the very first line of the description in the manual page...If it's not pointless it is an implementation bug.You can either get in your time machine and go back to 1978 and fix it, or add the cast like every C programmer who knows what the C standards say about these functions.So I took a moment to look. The C standard is indeed does not say anything about this and supporting signed char becomes a quality of implementation issue. glibc supports being passed signed character values.
You must have looked in the wrong place. The standards documentation on all the ctype functions is very clear about the valid input domain.
quoted
Testing on one implementation doesn't prove anything. 'char' can be signed or unsigned depending on the architecture, and some C libraries work around buggy applications that . That's no reason to write another buggy application.This code by it's very nature is not portable. The code is not suid so insane level of paranoia don't need to be maintained.
What!!!! You still don't want core dumps due to invalid input. Especially if the input might be from a file. I did the full trawl of NetBSD's 'src' tree because of issues with one of the shells faulting.
The definition in the C standard is a least common denominator requirement. Posix copies that least common denominator requirement. Glibc does not implment the least common denominator.
Unless you writes 'standards compliant' programs, you will eventually fall foul of these sort of problems. Are you sure that glibc will always be used? What about newlib? There may be strict requirements on isdigit() (I think you are allowed to subtract '0' to get a number). The same is not true of isprint(), isprint(EOF) is FALSE, isprint(255) may be TRUE (ij ligature). David