util_str.c and Problems with wins

Michael Stockman pgmtekn-micke at algonet.se
Mon Feb 14 20:33:00 GMT 2000


Hello Helmut,

Sorry if anyone have already pointed this out.

> By reading this part of code from samba 2.0.6 I found 2 possible
problems.
>
> 1) Function next_token:
> ...
> if (!ptr) ptr = &last_ptr;
> if (!ptr) return(False); // I think this should read as:
> if(!*ptr) return(False);
>
> s = *ptr;
>
> last_ptr is defined as static char *, and so it always returns an
address.

Yes, but the address may be NULL. Your code would check if the
character at adress ptr is '\0' rather than if ptr points at address
NULL. The original code is correct.

> 2) Function strhex_to_str:
> ....
> char *hexchars = "0123456789ABCDEF";
> ....
> for ( i = 0; i < len && strhex[i] != 0; i++ )
> {
> if( strnequal(hexchars, "0x", 2)) // I think
> this should be: if( strnequal(strhex +i, "0x", 2))
> {
> i++; /* skip 2 chars */
> ....
>
> the variable hexchars is unchanged in this function, so this test
never can
> be true.

This is probably correct.

> When this function should skip any non-hex-numeric characters (as
> described), then the following change should be done:
> Original:
> if (!(p1 = strchr(hexchars, toupper(strhex[i]))))
> {
> break;
> }
> i++;
> New:
> if (!(p1 = strchr(hexchars, toupper(strhex[i]))))
> {
> continue; /* the first character is
> non-hex-numeric, so skip that character */
> }
> i++;

Not entirely correct, this could actually make the function read past
a terminating '\0'. However your observation that it doesn't ignore
non hex digits correctly is correct.

Best regards
  Michael Stockman
  pgmtekn-micke at algonet.se

PS You are probably better of if I don't try to help you with wins.





More information about the samba-technical mailing list