summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brown2008-06-27 22:50:18 +0200
committerMichael Brown2008-06-27 22:50:18 +0200
commitddf5c8d4d3ae32df0b0d699f4fabb06dbfb37475 (patch)
treea62b0ac717b789d15bda37e75dc9be8e5568c632
parent[script] Remove arbitrary limit on script line lengths (diff)
downloadipxe-ddf5c8d4d3ae32df0b0d699f4fabb06dbfb37475.tar.gz
ipxe-ddf5c8d4d3ae32df0b0d699f4fabb06dbfb37475.tar.xz
ipxe-ddf5c8d4d3ae32df0b0d699f4fabb06dbfb37475.zip
[cmdline] Fix image command-line construction for zero-length argument lists
This fixes a bug introduced in commit 4c85017.
-rw-r--r--src/hci/commands/image_cmd.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/hci/commands/image_cmd.c b/src/hci/commands/image_cmd.c
index 23843a7e..b651078b 100644
--- a/src/hci/commands/image_cmd.c
+++ b/src/hci/commands/image_cmd.c
@@ -55,18 +55,21 @@ static int imgfill_cmdline ( struct image *image, unsigned int nargs,
/* Determine total length of command line */
len = 1; /* NUL */
for ( i = 0 ; i < nargs ; i++ )
- len += ( 1 /* space */ + strlen ( args[i] ) );
+ len += ( 1 /* possible space */ + strlen ( args[i] ) );
{
char buf[len];
char *ptr = buf;
/* Assemble command line */
- for ( i = 0 ; i < nargs ; i++ )
- ptr += sprintf ( ptr, " %s", args[i] );
- assert ( ptr == ( buf + len - 1 ) );
+ buf[0] = '\0';
+ for ( i = 0 ; i < nargs ; i++ ) {
+ ptr += sprintf ( ptr, "%s%s", ( i ? " " : "" ),
+ args[i] );
+ }
+ assert ( ptr < ( buf + len ) );
- return image_set_cmdline ( image, &buf[1] );
+ return image_set_cmdline ( image, buf );
}
}