You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Rodent of Unusual Size <co...@decus.org> on 1997/02/15 22:35:21 UTC
[PATCH] Fix for vbprintf("%s") and NULL pointers
The attached patch seems to do the trick. While it's sometimes
reasonable for a routine to die horribly if given bogus arguments,
vbprintf() extends printf(), so IMHO it shouldn't introduce a bug
in the basic printf functionality it's emulating.. ?
#ken :-)}
Index: http_bprintf.c
===================================================================
RCS file: /usr/users/coar/myApache/repository/apache/src/http_bprintf.c,v
retrieving revision 1.7
diff -c -r1.7 http_bprintf.c
*** 1.7 1996/11/03 20:36:34
--- http_bprintf.c 1997/02/15 21:32:23
***************
*** 42,47 ****
--- 42,51 ----
/*
* Max size of a format specifier is 1 + 5 + 7 + 7 + 2 + 1 + slop
*/
+ #define NULL_STRING "(null)"
+ /*
+ * String displayed if given a NULL pointer.
+ */
/*
* Copy n characters from *srcPtr to *destPtr, then increment
***************
*** 277,282 ****
--- 281,289 ----
case 's':
charPtrArg = va_arg(arg, char *);
+ if (charPtrArg == NULL) {
+ charPtrArg = NULL_STRING;
+ };
if(precision == -1)
buffReqd = strlen(charPtrArg);
else
***************
*** 444,449 ****
--- 451,459 ----
if(fastPath)
{
buffPtr = va_arg(arg, char *);
+ if (buffPtr == NULL) {
+ buffPtr = NULL_STRING;
+ };
buffCount = strlen(buffPtr);
buffLen = buffCount + 1;
}
Re: [PATCH] Fix for vbprintf("%s") and NULL pointers
Posted by Paul Richards <p....@elsevier.co.uk>.
Dean Gaudet <dg...@arctic.org> writes:
> > The attached patch seems to do the trick. While it's sometimes
> > reasonable for a routine to die horribly if given bogus arguments,
> > vbprintf() extends printf(), so IMHO it shouldn't introduce a bug
> > in the basic printf functionality it's emulating.. ?
This is totally wrong.
Passing a null reference to printf results in "undetermined"
behaviour. I really dislike printf's that try to be clever and print
(null). That's braindead behaviour in my opinion though it is allowed.
It's almost always the case that if you pass a null pointer to printf
it's because of a bug in your code and bugs in C code should result in
faults not non-fatal messages. Instead of having broken code fail
you've now made it work even though it's probably still broken.
This argument is akin to the one as to whether strcpy should check
for null pointers. It shouldn't, it's not the job of library functions
to protect the programmer from coding errors.
--
Dr Paul Richards. Originative Solutions Ltd. (Netcraft Ltd. contractor)
Elsevier Science TIS online journal project.
Email: p.richards@elsevier.co.uk
Phone: 0370 462071 (Mobile), +44 (0)1865 843155
Re: [PATCH] Fix for vbprintf("%s") and NULL pointers
Posted by Dean Gaudet <dg...@arctic.org>.
+1
On Sat, 15 Feb 1997, Rodent of Unusual Size wrote:
> The attached patch seems to do the trick. While it's sometimes
> reasonable for a routine to die horribly if given bogus arguments,
> vbprintf() extends printf(), so IMHO it shouldn't introduce a bug
> in the basic printf functionality it's emulating.. ?
>
> #ken :-)}
>
> Index: http_bprintf.c
> ===================================================================
> RCS file: /usr/users/coar/myApache/repository/apache/src/http_bprintf.c,v
> retrieving revision 1.7
> diff -c -r1.7 http_bprintf.c
> *** 1.7 1996/11/03 20:36:34
> --- http_bprintf.c 1997/02/15 21:32:23
> ***************
> *** 42,47 ****
> --- 42,51 ----
> /*
> * Max size of a format specifier is 1 + 5 + 7 + 7 + 2 + 1 + slop
> */
> + #define NULL_STRING "(null)"
> + /*
> + * String displayed if given a NULL pointer.
> + */
>
> /*
> * Copy n characters from *srcPtr to *destPtr, then increment
> ***************
> *** 277,282 ****
> --- 281,289 ----
>
> case 's':
> charPtrArg = va_arg(arg, char *);
> + if (charPtrArg == NULL) {
> + charPtrArg = NULL_STRING;
> + };
> if(precision == -1)
> buffReqd = strlen(charPtrArg);
> else
> ***************
> *** 444,449 ****
> --- 451,459 ----
> if(fastPath)
> {
> buffPtr = va_arg(arg, char *);
> + if (buffPtr == NULL) {
> + buffPtr = NULL_STRING;
> + };
> buffCount = strlen(buffPtr);
> buffLen = buffCount + 1;
> }
>