util_str.c and Problems with wins

Heinreichsberger Helmut helmut.heinreichsberger at sbs.at
Mon Feb 14 22:57:17 GMT 2000


Hello Michael,

My problem with wins is in discussion, but not by samba. I have got a work
around for this situation.


> -----Original Message-----
> From: Michael Stockman [mailto:pgmtekn-micke at algonet.se]
> Sent: Monday, February 14, 2000 9:33 PM
> To: Samba Technical; helmut.heinreichsberger at sbs.at
> Subject: Re: util_str.c and Problems with wins
> 
> 
> 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.

I hope that I can understand this 2 lines and would split it in two parts:

assignment to the source char **ptr.
If this Argument is NULL the we assign the Address of the static global
variable last_ptr (ptr = &last_ptr). Lets take this situation with last_ptr
= NULL, so the Address of last_ptr is a Value in the global data space, and
so the char **ptr got an Address in the global Data Area and not NULL. The
contents of char **ptr is NULL (the value of last_ptr), but not ptr.

checking if the source Address should be done with the contents of ptr,
because in the next line the Variable s gets the contents of ptr (in our
situation NULL), and few lines later the contents of s (possible the
contents of NULL) is taken for a while loop and so this while loop tries to
read characters from the Address NULL.

> 
> > 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.
> 
The terminating '\0' is handled by the break condition of the for loop. So
this continue only can be done by if( !(p1 ....) and not by the if(!(p2
...). To skip a bad second character is not described and so the loop should
break.

> 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.
> 
> 

Best regards
Helmut Heinreichsberger
Helmut.Heinreichsberger at sbs.at

PS: At the moment I only can read the mailing Archives, so I don't know if
anyone else has answered.


More information about the samba-technical mailing list