Skip to content

Commit

Permalink
Fix GCC format-security errors and convert sprintfs.
Browse files Browse the repository at this point in the history
With format-security errors turned on, GCC picks up the use of sprintf with
a format parameter not being a string literal.

Simple uses of sprintf are also converted to use strcpy.

Signed-off-by: Ben Whitten <[email protected]>
Acked-by: Wolfgang Denk <[email protected]>
Reviewed-by: Tom Rini <[email protected]>
  • Loading branch information
BWhitten authored and trini committed Jan 15, 2016
1 parent 4edde96 commit 192bc69
Show file tree
Hide file tree
Showing 53 changed files with 75 additions and 72 deletions.
2 changes: 1 addition & 1 deletion arch/mips/mach-au1x00/au1x00_eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ int au1x00_enet_initialize(bd_t *bis){

memset(dev, 0, sizeof *dev);

sprintf(dev->name, "Au1X00 ethernet");
strcpy(dev->name, "Au1X00 ethernet");
dev->iobase = 0;
dev->priv = 0;
dev->init = au1x00_init;
Expand Down
2 changes: 1 addition & 1 deletion arch/powerpc/cpu/mpc8260/ether_scc.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ int mpc82xx_scc_enet_initialize(bd_t *bis)
dev = (struct eth_device *) malloc(sizeof *dev);
memset(dev, 0, sizeof *dev);

sprintf(dev->name, "SCC");
strcpy(dev->name, "SCC");
dev->init = sec_init;
dev->halt = sec_halt;
dev->send = sec_send;
Expand Down
2 changes: 1 addition & 1 deletion arch/powerpc/cpu/mpc8xx/fec.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ int fec_initialize(bd_t *bis)
/* for FEC1 make sure that the name of the interface is the same
as the old one for compatibility reasons */
if (i == 0) {
sprintf (dev->name, "FEC");
strcpy(dev->name, "FEC");
} else {
sprintf (dev->name, "FEC%d",
ether_fcc_info[i].ether_index + 1);
Expand Down
2 changes: 1 addition & 1 deletion arch/powerpc/cpu/mpc8xx/scc.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ int scc_initialize(bd_t *bis)
dev = (struct eth_device*) malloc(sizeof *dev);
memset(dev, 0, sizeof *dev);

sprintf(dev->name, "SCC");
strcpy(dev->name, "SCC");
dev->iobase = 0;
dev->priv = 0;
dev->init = scc_init;
Expand Down
4 changes: 2 additions & 2 deletions arch/powerpc/cpu/mpc8xx/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -981,11 +981,11 @@ static void *video_logo (void)
U_BOOT_VERSION, U_BOOT_DATE, U_BOOT_TIME);
video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y, info);

sprintf (info, "(C) 2002 DENX Software Engineering");
strcpy(info, "(C) 2002 DENX Software Engineering");
video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
info);

sprintf (info, " Wolfgang DENK, [email protected]");
strcpy(info, " Wolfgang DENK, [email protected]");
video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 2,
info);

Expand Down
8 changes: 4 additions & 4 deletions board/freescale/b4860qds/eth_b4860qds.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,22 +408,22 @@ void board_ft_fman_fixup_port(void *fdt, char *compat, phys_addr_t addr,
sizeof(f_link));
break;
case 0x98: /* XAUI interface */
sprintf(alias, "phy_xaui_slot1");
strcpy(alias, "phy_xaui_slot1");
fdt_status_okay_by_alias(fdt, alias);

sprintf(alias, "phy_xaui_slot2");
strcpy(alias, "phy_xaui_slot2");
fdt_status_okay_by_alias(fdt, alias);
break;
case 0x9e: /* XAUI interface */
case 0x9a:
case 0x93:
case 0x91:
sprintf(alias, "phy_xaui_slot1");
strcpy(alias, "phy_xaui_slot1");
fdt_status_okay_by_alias(fdt, alias);
break;
case 0x97: /* XAUI interface */
case 0xc3:
sprintf(alias, "phy_xaui_slot2");
strcpy(alias, "phy_xaui_slot2");
fdt_status_okay_by_alias(fdt, alias);
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion board/freescale/corenet_ds/eth_hydra.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ static int hydra_mdio_init(char *realbusname, char *fakebusname)
bus->read = hydra_mdio_read;
bus->write = hydra_mdio_write;
bus->reset = hydra_mdio_reset;
sprintf(bus->name, fakebusname);
strcpy(bus->name, fakebusname);

hmdio->realbus = miiphy_get_dev_by_name(realbusname);

Expand Down
2 changes: 1 addition & 1 deletion board/freescale/corenet_ds/eth_superhydra.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ static int super_hydra_mdio_init(char *realbusname, char *fakebusname)
bus->read = super_hydra_mdio_read;
bus->write = super_hydra_mdio_write;
bus->reset = super_hydra_mdio_reset;
sprintf(bus->name, fakebusname);
strcpy(bus->name, fakebusname);

hmdio->realbus = miiphy_get_dev_by_name(realbusname);

Expand Down
2 changes: 1 addition & 1 deletion board/freescale/ls1021aqds/eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ static int ls1021a_mdio_init(char *realbusname, char *fakebusname)
bus->read = ls1021a_mdio_read;
bus->write = ls1021a_mdio_write;
bus->reset = ls1021a_mdio_reset;
sprintf(bus->name, fakebusname);
strcpy(bus->name, fakebusname);

lsmdio->realbus = miiphy_get_dev_by_name(realbusname);

Expand Down
2 changes: 1 addition & 1 deletion board/freescale/ls1043aqds/eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ static int ls1043aqds_mdio_init(char *realbusname, u8 muxval)
bus->read = ls1043aqds_mdio_read;
bus->write = ls1043aqds_mdio_write;
bus->reset = ls1043aqds_mdio_reset;
sprintf(bus->name, ls1043aqds_mdio_name_for_muxval(muxval));
strcpy(bus->name, ls1043aqds_mdio_name_for_muxval(muxval));

pmdio->realbus = miiphy_get_dev_by_name(realbusname);

Expand Down
2 changes: 1 addition & 1 deletion board/freescale/ls2080aqds/eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ static int ls2080a_qds_mdio_init(char *realbusname, u8 muxval)
bus->read = ls2080a_qds_mdio_read;
bus->write = ls2080a_qds_mdio_write;
bus->reset = ls2080a_qds_mdio_reset;
sprintf(bus->name, ls2080a_qds_mdio_name_for_muxval(muxval));
strcpy(bus->name, ls2080a_qds_mdio_name_for_muxval(muxval));

pmdio->realbus = miiphy_get_dev_by_name(realbusname);

Expand Down
2 changes: 1 addition & 1 deletion board/freescale/t102xqds/eth_t102xqds.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ static int t1024qds_mdio_init(char *realbusname, u8 muxval)
bus->read = t1024qds_mdio_read;
bus->write = t1024qds_mdio_write;
bus->reset = t1024qds_mdio_reset;
sprintf(bus->name, t1024qds_mdio_name_for_muxval(muxval));
strcpy(bus->name, t1024qds_mdio_name_for_muxval(muxval));

pmdio->realbus = miiphy_get_dev_by_name(realbusname);

Expand Down
2 changes: 1 addition & 1 deletion board/freescale/t1040qds/eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ static int t1040_qds_mdio_init(char *realbusname, u8 muxval)
bus->read = t1040_qds_mdio_read;
bus->write = t1040_qds_mdio_write;
bus->reset = t1040_qds_mdio_reset;
sprintf(bus->name, t1040_qds_mdio_name_for_muxval(muxval));
strcpy(bus->name, t1040_qds_mdio_name_for_muxval(muxval));

pmdio->realbus = miiphy_get_dev_by_name(realbusname);

Expand Down
2 changes: 1 addition & 1 deletion board/freescale/t208xqds/eth_t208xqds.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ static int t208xqds_mdio_init(char *realbusname, u8 muxval)
bus->read = t208xqds_mdio_read;
bus->write = t208xqds_mdio_write;
bus->reset = t208xqds_mdio_reset;
sprintf(bus->name, t208xqds_mdio_name_for_muxval(muxval));
strcpy(bus->name, t208xqds_mdio_name_for_muxval(muxval));

pmdio->realbus = miiphy_get_dev_by_name(realbusname);

Expand Down
2 changes: 1 addition & 1 deletion board/freescale/t4qds/eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ static int t4240qds_mdio_init(char *realbusname, u8 muxval)
bus->read = t4240qds_mdio_read;
bus->write = t4240qds_mdio_write;
bus->reset = t4240qds_mdio_reset;
sprintf(bus->name, t4240qds_mdio_name_for_muxval(muxval));
strcpy(bus->name, t4240qds_mdio_name_for_muxval(muxval));

pmdio->realbus = miiphy_get_dev_by_name(realbusname);

Expand Down
2 changes: 1 addition & 1 deletion board/gdsys/common/ihs_mdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ int ihs_mdio_init(struct ihs_mdio_info *info)
bus->read = ihs_mdio_read;
bus->write = ihs_mdio_write;
bus->reset = ihs_mdio_reset;
sprintf(bus->name, info->name);
strcpy(bus->name, info->name);

bus->priv = info;

Expand Down
4 changes: 2 additions & 2 deletions board/keymile/common/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ static int do_setboardid(cmd_tbl_t *cmdtp, int flag, int argc,
printf("can't get the IVM_Boardid\n");
return 1;
}
sprintf((char *)buf, "%s", p);
strcpy((char *)buf, p);
setenv("boardid", (char *)buf);
printf("set boardid=%s\n", buf);

Expand All @@ -177,7 +177,7 @@ static int do_setboardid(cmd_tbl_t *cmdtp, int flag, int argc,
printf("can't get the IVM_HWKey\n");
return 1;
}
sprintf((char *)buf, "%s", p);
strcpy((char *)buf, p);
setenv("hwkey", (char *)buf);
printf("set hwkey=%s\n", buf);
printf("Execute manually saveenv for persistent storage.\n");
Expand Down
8 changes: 4 additions & 4 deletions board/mpl/common/common_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -698,12 +698,12 @@ void video_get_info_str (int line_number, char *info)
s=getenv ("serial#");
#ifdef CONFIG_PIP405
if (!s || strncmp (s, "PIP405", 6)) {
sprintf(buf,"### No HW ID - assuming PIP405");
strcpy(buf,"### No HW ID - assuming PIP405");
}
#endif
#ifdef CONFIG_MIP405
if (!s || strncmp (s, "MIP405", 6)) {
sprintf(buf,"### No HW ID - assuming MIP405");
strcpy(buf,"### No HW ID - assuming MIP405");
}
#endif
else {
Expand All @@ -718,7 +718,7 @@ void video_get_info_str (int line_number, char *info)
}
buf[i++] = *s;
}
sprintf(&buf[i]," SN ");
strcpy(&buf[i]," SN ");
i+=4;
for (; s < e; ++s) {
buf[i++] = *s;
Expand All @@ -744,7 +744,7 @@ void video_get_info_str (int line_number, char *info)
ctfb.modeIdent);
return;
case 1:
sprintf (buf, "%s",CONFIG_IDENT_STRING);
strcpy(buf, CONFIG_IDENT_STRING);
sprintf (info, " %s", &buf[1]);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions board/samsung/universal_c210/universal.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,10 @@ int exynos_init(void)
}

/* Request soft I2C gpios */
sprintf(buf, "soft_i2c_scl");
strcpy(buf, "soft_i2c_scl");
gpio_request(CONFIG_SOFT_I2C_GPIO_SCL, buf);

sprintf(buf, "soft_i2c_sda");
strcpy(buf, "soft_i2c_sda");
gpio_request(CONFIG_SOFT_I2C_GPIO_SDA, buf);

check_hw_revision();
Expand Down
2 changes: 1 addition & 1 deletion board/siemens/rut/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ int board_late_init(void)
sprintf(tmp, "%s_%s", factory_dat.asn,
factory_dat.comp_version);
else
sprintf(tmp, "QMX7.E38_4.0");
strcpy(tmp, "QMX7.E38_4.0");

ret = setenv("boardid", tmp);
if (ret)
Expand Down
2 changes: 1 addition & 1 deletion board/vscom/baltos/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ int board_late_init(void)

/* get production data */
if (read_eeprom(&header)) {
sprintf(model, "211");
strcpy(model, "211");
} else {
sprintf(model, "%d", header.SystemId);
if (header.SystemId == 215) {
Expand Down
13 changes: 8 additions & 5 deletions common/cmd_elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,10 @@ int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
(size_t)255));
} else {
tmp = getenv("bootdev");
if (tmp)
ptr = sprintf(build_buf, tmp);
else
if (tmp) {
strcpy(build_buf, tmp);
ptr = strlen(tmp);
} else
printf("## VxWorks boot device not specified\n");

tmp = getenv("bootfile");
Expand Down Expand Up @@ -331,8 +332,10 @@ int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
ptr += sprintf(build_buf + ptr, "tn=%s ", tmp);

tmp = getenv("othbootargs");
if (tmp)
ptr += sprintf(build_buf + ptr, tmp);
if (tmp) {
strcpy(build_buf + ptr, tmp);
ptr += strlen(tmp);
}

memcpy((void *)bootaddr, build_buf,
max(strlen(build_buf), (size_t)255));
Expand Down
2 changes: 1 addition & 1 deletion common/cmd_mtdparts.c
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ static int generate_mtdparts(char *buf, u32 buflen)
return 0;
}

sprintf(p, "mtdparts=");
strcpy(p, "mtdparts=");
p += 9;

list_for_each(dentry, &devices) {
Expand Down
4 changes: 2 additions & 2 deletions disk/part_dos.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ static int get_partition_info_extended (block_dev_desc_t *dev_desc,
break;
}
/* sprintf(info->type, "%d, pt->sys_ind); */
sprintf ((char *)info->type, "U-Boot");
strcpy((char *)info->type, "U-Boot");
info->bootable = is_bootable(pt);
#ifdef CONFIG_PARTITION_UUIDS
sprintf(info->uuid, "%08x-%02x", disksig, part_num);
Expand Down Expand Up @@ -273,7 +273,7 @@ static int get_partition_info_extended (block_dev_desc_t *dev_desc,
info->size = dev_desc->lba;
info->blksz = DOS_PART_DEFAULT_SECTOR;
info->bootable = 0;
sprintf ((char *)info->type, "U-Boot");
strcpy((char *)info->type, "U-Boot");
#ifdef CONFIG_PARTITION_UUIDS
info->uuid[0] = 0;
#endif
Expand Down
2 changes: 1 addition & 1 deletion disk/part_efi.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ int get_partition_info_efi(block_dev_desc_t * dev_desc, int part,

sprintf((char *)info->name, "%s",
print_efiname(&gpt_pte[part - 1]));
sprintf((char *)info->type, "U-Boot");
strcpy((char *)info->type, "U-Boot");
info->bootable = is_bootable(&gpt_pte[part - 1]);
#ifdef CONFIG_PARTITION_UUIDS
uuid_bin_to_str(gpt_pte[part - 1].unique_partition_guid.b, info->uuid,
Expand Down
2 changes: 1 addition & 1 deletion disk/part_iso.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ int get_partition_info_iso_verb(block_dev_desc_t * dev_desc, int part_num, disk_
/* the validation entry seems to be ok, now search the "partition" */
entry_num=0;
offset=0x20;
sprintf ((char *)info->type, "U-Boot");
strcpy((char *)info->type, "U-Boot");
switch(dev_desc->if_type) {
case IF_TYPE_IDE:
case IF_TYPE_SATA:
Expand Down
4 changes: 2 additions & 2 deletions drivers/block/sata_dwc.c
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ int scan_sata(int dev)
if (id[162] & 1)
printf("supports DRM functions and may "
"not be fully accessable.\n");
sprintf(revbuf, "%s", "CFA");
strcpy(revbuf, "CFA");
} else {
if (ata_id_has_tpm(id))
printf("supports DRM functions and may "
Expand All @@ -653,7 +653,7 @@ int scan_sata(int dev)
ncq_desc[0] = '\0';

if (ata_dev->horkage & ATA_HORKAGE_NONCQ)
sprintf(ncq_desc, "%s", "NCQ (not used)");
strcpy(ncq_desc, "NCQ (not used)");

if (ap.flags & ATA_FLAG_NCQ)
ata_dev->flags |= ATA_DFLAG_NCQ;
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/altera_tse.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ static int tse_mdio_init(const char *name, struct altera_tse_priv *priv)

bus->read = tse_mdio_read;
bus->write = tse_mdio_write;
snprintf(bus->name, sizeof(bus->name), name);
snprintf(bus->name, sizeof(bus->name), "%s", name);

bus->priv = (void *)priv;

Expand Down
2 changes: 1 addition & 1 deletion drivers/net/at91_emac.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ int at91emac_register(bd_t *bis, unsigned long iobase)
memset(emacfix, 0, sizeof(emac_device));

memset(dev, 0, sizeof(*dev));
sprintf(dev->name, "emac");
strcpy(dev->name, "emac");
dev->iobase = iobase;
dev->priv = emacfix;
dev->init = at91emac_init;
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ax88180.c
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ int ax88180_initialize (bd_t * bis)

memset (priv, 0, sizeof *priv);

sprintf (dev->name, "ax88180");
strcpy(dev->name, "ax88180");
dev->iobase = AX88180_BASE;
dev->priv = priv;
dev->init = ax88180_init;
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/cpsw.c
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ static void cpsw_mdio_init(const char *name, u32 mdio_base, u32 div)

bus->read = cpsw_mdio_read;
bus->write = cpsw_mdio_write;
sprintf(bus->name, name);
strcpy(bus->name, name);

mdio_register(bus);
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/davinci_emac.c
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ int davinci_emac_initialize(void)
return -1;

memset(dev, 0, sizeof *dev);
sprintf(dev->name, "DaVinci-EMAC");
strcpy(dev->name, "DaVinci-EMAC");

dev->iobase = 0;
dev->init = davinci_eth_open;
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/designware.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static int dw_mdio_init(const char *name, struct eth_mac_regs *mac_regs_p)

bus->read = dw_mdio_read;
bus->write = dw_mdio_write;
snprintf(bus->name, sizeof(bus->name), name);
snprintf(bus->name, sizeof(bus->name), "%s", name);

bus->priv = (void *)mac_regs_p;

Expand Down
Loading

0 comments on commit 192bc69

Please sign in to comment.