name resolve order

Andrew Tridgell tridge at
Tue Mar 17 00:30:16 GMT 1998

> Please look over the new stuff (it's documented
> also) - I put it in 1.9.18 and the head branches
> and try and break it :-).


I've had a quick look and found a small bug. I'm CCing this list
because others may not be aware of some of the details of the string
handling functions in Samba (Luke, you may find this useful!). 

You have code like this:

  for (p=strtok(lp_name_resolve_order(),LIST_SEP); p; p = strtok(NULL,LIST_SEP)) {
     /* look at p and decide what to do */

that will work most of the time, but may sometimes mysteriously fail!

The problem is the use of strtok() with a lp_* function that returns a
string. The lp_* string functions put their result into a circular
list of string buffers. That means you can change them, but you had
better not be still using the string when you loop around in the
circular list and hit the same one again.

If the functions you call inside this loop happen to make more than N
calls (N is currently 10) to a lp_* string function then the original
buffer will be corrupted. As you call wins and other functions this
could easily happen.

The correct fix is to strdup() the list then free it or copy it to a
pstring before parsing it. 

The other minor bug is the use of strtok() in a non-leaf
routine. strtok() uses static data an thus you can't call one strtok
inside another without corruption. That's why we have the
next_token() function in Samba, it doesn't use any static data.

Sorry to be so picky, but I thought it was worth explaining :-)

Cheers, Andrew

More information about the samba-technical mailing list