mirror of https://github.com/ipxe/ipxe.git
[uri] Handle an empty unparse_uri() result properly
Previously, if none of the URI parts requested existed in the passed URI, unparse_uri() would not touch the destination buffer at all; this could lead to use of uninitialized data. Fix by setting buf[0] = '\0' before unparsing whenever we have room to do so. Signed-off-by: Joshua Oreman <oremanj@rwcr.net> Signed-off-by: Marty Connor <mdc@etherboot.org>pull/1/head
parent
329c7b78e3
commit
e6f08b0aa7
|
@ -225,12 +225,13 @@ int unparse_uri ( char *buf, size_t size, struct uri *uri,
|
||||||
dump_uri ( uri );
|
dump_uri ( uri );
|
||||||
DBG ( "\n" );
|
DBG ( "\n" );
|
||||||
|
|
||||||
|
/* Ensure buffer is NUL-terminated */
|
||||||
|
if ( size )
|
||||||
|
buf[0] = '\0';
|
||||||
|
|
||||||
/* Special-case NULL URI */
|
/* Special-case NULL URI */
|
||||||
if ( ! uri ) {
|
if ( ! uri )
|
||||||
if ( size )
|
|
||||||
buf[0] = '\0';
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
/* Iterate through requested fields */
|
/* Iterate through requested fields */
|
||||||
for ( i = URI_FIRST_FIELD; i <= URI_LAST_FIELD; i++ ) {
|
for ( i = URI_FIRST_FIELD; i <= URI_LAST_FIELD; i++ ) {
|
||||||
|
|
Loading…
Reference in New Issue