mirror of https://github.com/ipxe/ipxe.git
[cmdline] Fix image command-line construction for zero-length argument lists
This fixes a bug introduced in commit 4c85017
.
pull/1/head
parent
0ea821c7b7
commit
ddf5c8d4d3
|
@ -55,18 +55,21 @@ static int imgfill_cmdline ( struct image *image, unsigned int nargs,
|
||||||
/* Determine total length of command line */
|
/* Determine total length of command line */
|
||||||
len = 1; /* NUL */
|
len = 1; /* NUL */
|
||||||
for ( i = 0 ; i < nargs ; i++ )
|
for ( i = 0 ; i < nargs ; i++ )
|
||||||
len += ( 1 /* space */ + strlen ( args[i] ) );
|
len += ( 1 /* possible space */ + strlen ( args[i] ) );
|
||||||
|
|
||||||
{
|
{
|
||||||
char buf[len];
|
char buf[len];
|
||||||
char *ptr = buf;
|
char *ptr = buf;
|
||||||
|
|
||||||
/* Assemble command line */
|
/* Assemble command line */
|
||||||
for ( i = 0 ; i < nargs ; i++ )
|
buf[0] = '\0';
|
||||||
ptr += sprintf ( ptr, " %s", args[i] );
|
for ( i = 0 ; i < nargs ; i++ ) {
|
||||||
assert ( ptr == ( buf + len - 1 ) );
|
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 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue