confused by decodeString() routine in httpd.c

Robert P. J. Day rpjday at mindspring.com
Sat Apr 15 20:20:23 UTC 2006


  just perusing httpd.c in preparation for trying to add some features
and i'm a bit baffled by the implementation of the routine
decodeString(), to decode a URL-encoded string.

  i can see that you can run "httpd" with "-d" to decode a string, so
i'm curious about this excerpt:

	if(sscanf(ptr, "%1X", &value1) != 1 ||
                                sscanf(ptr+1, "%1X", &value2) != 1) {
          if(!flag_plus_to_space)
                return NULL;
          *string++ = '%';
        } else {
          value1 = value1 * 16 + value2;
          if(value1 == '/' || value1 == 0)    <-- ????
                return orig+1;


  that seems to suggest that, if the last encoded character is a "/",
it won't be decoded and the return value will be, not the first
character of the argument string, but the second, which disagrees with
the documentation.

  for example:

$ ./httpd -d abc/
abc/$
^^^^  (looks good)

$ ./httpd -d abc%2f
bc%2f$   (huh?  what happened to the 'a'?)

  is that the expected behaviour?

rday




More information about the busybox mailing list