david/ipxe
david
/
ipxe
Archived
1
0
Fork 0

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

This fixes a bug introduced in commit 4c85017.
This commit is contained in:
Michael Brown 2008-06-27 21:50:18 +01:00
parent 0ea821c7b7
commit ddf5c8d4d3
1 changed files with 8 additions and 5 deletions

View File

@ -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 );
}
}