summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoshua Oreman2010-01-27 05:55:23 +0100
committerMarty Connor2010-01-27 14:50:49 +0100
commite6f08b0aa79a07bcadff203c91245db0dcd155b7 (patch)
tree1511772d0d79bdd7b324d4e6ecdb941345d00436
parent[release] Update version to 1.0.0-rc1+ post release (diff)
downloadipxe-e6f08b0aa79a07bcadff203c91245db0dcd155b7.tar.gz
ipxe-e6f08b0aa79a07bcadff203c91245db0dcd155b7.tar.xz
ipxe-e6f08b0aa79a07bcadff203c91245db0dcd155b7.zip
[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>
-rw-r--r--src/core/uri.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/core/uri.c b/src/core/uri.c
index 96667782..6a1f2e59 100644
--- a/src/core/uri.c
+++ b/src/core/uri.c
@@ -225,12 +225,13 @@ int unparse_uri ( char *buf, size_t size, struct uri *uri,
dump_uri ( uri );
DBG ( "\n" );
+ /* Ensure buffer is NUL-terminated */
+ if ( size )
+ buf[0] = '\0';
+
/* Special-case NULL URI */
- if ( ! uri ) {
- if ( size )
- buf[0] = '\0';
+ if ( ! uri )
return 0;
- }
/* Iterate through requested fields */
for ( i = URI_FIRST_FIELD; i <= URI_LAST_FIELD; i++ ) {