Instead use strdup() so that we can dynamically allocate the string ourselves. As reported by Rob Landley rob@landley.net.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- openbios-devel/arch/sparc32/openbios.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/openbios-devel/arch/sparc32/openbios.c b/openbios-devel/arch/sparc32/openbios.c index 95a5d37..56bafe8 100644 --- a/openbios-devel/arch/sparc32/openbios.c +++ b/openbios-devel/arch/sparc32/openbios.c @@ -835,8 +835,7 @@ static void init_memory(void) static void arch_init( void ) { - static char cmdline[128]; - int size = 0; + char *cmdline = { '\0' }; const char *kernel_cmdline; uint32_t temp; uint16_t machine_id; @@ -897,11 +896,9 @@ arch_init( void )
kernel_cmdline = (const char *) fw_cfg_read_i32(FW_CFG_KERNEL_CMDLINE); if (kernel_cmdline) { - size = strlen(kernel_cmdline); - memcpy(cmdline, kernel_cmdline, size); + cmdline = strdup(kernel_cmdline); obp_arg.argv[1] = cmdline; } - cmdline[size] = '\0'; qemu_cmdline = (uint32_t)cmdline;
/* Setup nvram variables */
Instead use strdup() so that we can dynamically allocate the string ourselves. As reported by Rob Landley rob@landley.net.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- openbios-devel/arch/sparc64/openbios.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/openbios-devel/arch/sparc64/openbios.c b/openbios-devel/arch/sparc64/openbios.c index 3b372b9..440e505 100644 --- a/openbios-devel/arch/sparc64/openbios.c +++ b/openbios-devel/arch/sparc64/openbios.c @@ -42,9 +42,6 @@ #define NVRAM_OB_START (0) #define NVRAM_OB_SIZE ((0x1fd0 - NVRAM_OB_START) & ~15)
-#define OBIO_CMDLINE_MAX 256 -static char obio_cmdline[OBIO_CMDLINE_MAX]; - static uint8_t idprom[NVRAM_IDPROM_SIZE];
struct hwdef { @@ -370,6 +367,7 @@ static uint8_t qemu_uuid[16];
void arch_nvram_get(char *data) { + char *obio_cmdline = { '\0' }; uint32_t size = 0; const struct cpudef *cpu; char buf[256]; @@ -401,12 +399,11 @@ void arch_nvram_get(char *data) kernel_image = fw_cfg_read_i64(FW_CFG_KERNEL_ADDR);
size = fw_cfg_read_i32(FW_CFG_CMDLINE_SIZE); - if (size > OBIO_CMDLINE_MAX - 1) - size = OBIO_CMDLINE_MAX - 1; if (size) { + obio_cmdline = (char *)malloc(size + 1); fw_cfg_read(FW_CFG_CMDLINE_DATA, obio_cmdline, size); - } - obio_cmdline[size] = '\0'; + obio_cmdline[size] = '\0'; + } qemu_cmdline = (uint64_t)obio_cmdline; cmdline_size = size; boot_device = fw_cfg_read_i16(FW_CFG_BOOT_DEVICE);
On Fri, Apr 12, 2013 at 2:13 PM, Mark Cave-Ayland mark.cave-ayland@ilande.co.uk wrote:
Instead use strdup() so that we can dynamically allocate the string ourselves. As
Actually there's no call to strdup()...
reported by Rob Landley rob@landley.net.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk
openbios-devel/arch/sparc64/openbios.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/openbios-devel/arch/sparc64/openbios.c b/openbios-devel/arch/sparc64/openbios.c index 3b372b9..440e505 100644 --- a/openbios-devel/arch/sparc64/openbios.c +++ b/openbios-devel/arch/sparc64/openbios.c @@ -42,9 +42,6 @@ #define NVRAM_OB_START (0) #define NVRAM_OB_SIZE ((0x1fd0 - NVRAM_OB_START) & ~15)
-#define OBIO_CMDLINE_MAX 256 -static char obio_cmdline[OBIO_CMDLINE_MAX];
static uint8_t idprom[NVRAM_IDPROM_SIZE];
struct hwdef { @@ -370,6 +367,7 @@ static uint8_t qemu_uuid[16];
void arch_nvram_get(char *data) {
- char *obio_cmdline = { '\0' };
Isn't this allocated in the stack? So ...
uint32_t size = 0; const struct cpudef *cpu; char buf[256];
@@ -401,12 +399,11 @@ void arch_nvram_get(char *data) kernel_image = fw_cfg_read_i64(FW_CFG_KERNEL_ADDR);
size = fw_cfg_read_i32(FW_CFG_CMDLINE_SIZE);
- if (size > OBIO_CMDLINE_MAX - 1)
if (size) {size = OBIO_CMDLINE_MAX - 1;
obio_cmdline = (char *)malloc(size + 1); fw_cfg_read(FW_CFG_CMDLINE_DATA, obio_cmdline, size);
- }
- obio_cmdline[size] = '\0';
obio_cmdline[size] = '\0';
- }
... I'd add an 'else' case here with something like obio_cmdline = strdup("").
qemu_cmdline = (uint64_t)obio_cmdline; cmdline_size = size; boot_device = fw_cfg_read_i16(FW_CFG_BOOT_DEVICE);
-- 1.7.10.4
-- OpenBIOS http://openbios.org/ Mailinglist: http://lists.openbios.org/mailman/listinfo Free your System - May the Forth be with you