Re: sprintf and strings with NULL byte

From: Date: Wed, 25 Apr 2001 21:19:13 +0000
Subject: Re: sprintf and strings with NULL byte
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-52439@lists.php.net to get a copy of this message
> > As for the %*s issue. We are passing in the length of the string arg in > > the call: > > > > php_sprintf_appendstring(&result, &outpos, &size, > > (*args[argnum])->value.str.val, > > width, precision, padding, > > alignment, > > (*args[argnum])->value.str.len, > > 0, expprec); > > > > So we have the info. In php_sprintf_appendstring() the replacement is > > done using: > > > > strncpy(&(*buffer)[*pos], add, MIN(max_width, len)+1); > > > > Looks like simply changing this to a memcpy() call will fix this. Again, > > I don't see any reason not to make this change. PHP is supposed to be > > 8-bit clean and I think this should extend to the printf functions as > > well. > > That's fine, but I'm not talking about userland sprintf(), but rather > using C library sprintf() call from inside one of my extension > functions. If glibc sprintf() doesn't handle NULL bytes, do we have a > replacement for it in PHP aside from php_formatted_print() which expects > to receive its arguments from a script? Oh, and I went and fixed this anyway. I'd just split that php_formatted_print() function into two parts. One that does the argument handling and one that just does the work like we have done with so many other functions. -Rasmus

« previous php.dev (#52439) next »