Browse Source

[cmdline] Fix image command-line construction for zero-length argument lists

This fixes a bug introduced in commit 4c85017.
tags/v0.9.4
Michael Brown 16 years ago
parent
commit
ddf5c8d4d3
1 changed files with 8 additions and 5 deletions
  1. 8
    5
      src/hci/commands/image_cmd.c

+ 8
- 5
src/hci/commands/image_cmd.c View File

@@ -55,18 +55,21 @@ static int imgfill_cmdline ( struct image *image, unsigned int nargs,
55 55
 	/* Determine total length of command line */
56 56
 	len = 1; /* NUL */
57 57
 	for ( i = 0 ; i < nargs ; i++ )
58
-		len += ( 1 /* space */ + strlen ( args[i] ) );
58
+		len += ( 1 /* possible space */ + strlen ( args[i] ) );
59 59
 
60 60
 	{
61 61
 		char buf[len];
62 62
 		char *ptr = buf;
63 63
 
64 64
 		/* Assemble command line */
65
-		for ( i = 0 ; i < nargs ; i++ )
66
-			ptr += sprintf ( ptr, " %s", args[i] );
67
-		assert ( ptr == ( buf + len - 1 ) );
65
+		buf[0] = '\0';
66
+		for ( i = 0 ; i < nargs ; i++ ) {
67
+			ptr += sprintf ( ptr, "%s%s", ( i ? " " : "" ),
68
+					 args[i] );
69
+		}
70
+		assert ( ptr < ( buf + len ) );
68 71
 
69
-		return image_set_cmdline ( image, &buf[1] );
72
+		return image_set_cmdline ( image, buf );
70 73
 	}
71 74
 }
72 75
 

Loading…
Cancel
Save