Browse Source

[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>
tags/v1.0.0
Joshua Oreman 14 years ago
parent
commit
e6f08b0aa7
1 changed files with 5 additions and 4 deletions
  1. 5
    4
      src/core/uri.c

+ 5
- 4
src/core/uri.c View File

@@ -225,12 +225,13 @@ int unparse_uri ( char *buf, size_t size, struct uri *uri,
225 225
 	dump_uri ( uri );
226 226
 	DBG ( "\n" );
227 227
 
228
+	/* Ensure buffer is NUL-terminated */
229
+	if ( size )
230
+		buf[0] = '\0';
231
+
228 232
 	/* Special-case NULL URI */
229
-	if ( ! uri ) {
230
-		if ( size )
231
-			buf[0] = '\0';
233
+	if ( ! uri )
232 234
 		return 0;
233
-	}
234 235
 
235 236
 	/* Iterate through requested fields */
236 237
 	for ( i = URI_FIRST_FIELD; i <= URI_LAST_FIELD; i++ ) {

Loading…
Cancel
Save