Skip to contentSkip to conversation

Fix GCC format-security errors.

PATCH Superseded ben.whitten at gmail.com 3 participants 6 messages Dec 29, 2015 – Jan 15, 2016

Subsystems (8)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix GCC format-security errors.

From: Ben Whitten <[email protected]>

With format-security errors turned on, GCC picks up the use of sprintf without a format parameter.

---
 common/cmd_elf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
common/cmd_elf.c +2 -2
index 86e694a..3677702 100644
@@ -289,7 +289,7 @@ int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		} else {
 			tmp = getenv("bootdev");
 			if (tmp)
-				ptr = sprintf(build_buf, tmp);
+				ptr = sprintf(build_buf, "%s", tmp);
 			else
 				printf("## VxWorks boot device not specified\n");
 
@@ -332,7 +332,7 @@ int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 			tmp = getenv("othbootargs");
 			if (tmp)
-				ptr += sprintf(build_buf + ptr, tmp);
+				ptr += sprintf(build_buf + ptr, "%s", tmp);
 
 			memcpy((void *)bootaddr, build_buf,
 			       max(strlen(build_buf), (size_t)255));

--
2.6.4

#1 lore raw

PATCH 1/1 Fix GCC format-security errors.

Dear Ben,

Quoted 4 lines · In message <[email protected]> you wrote:

From: Ben Whitten <[email protected]>

With format-security errors turned on, GCC picks up the use of sprintf without a format parameter.

Thanks for detecting this, but...

Quoted 2 lines
common/cmd_elf.c +1 -1
-				ptr = sprintf(build_buf, tmp);
+				ptr = sprintf(build_buf, "%s", tmp);

...

common/cmd_elf.c int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) · line 335

Quoted 2 lines
common/cmd_elf.c +1 -1
-				ptr += sprintf(build_buf + ptr, tmp);
+				ptr += sprintf(build_buf + ptr, "%s", tmp);

... why should we use sprintf() here at all? I recommend to convert this into a plain strcpy().

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Any fool can make things bigger, more complex, and more  violent.  It
takes  a  touch  of  genius  -  and a lot of courage - to move in the
opposite direction.                                 - Albert Einstein
#2 lore raw

PATCH v2 1/1 Fix GCC format-security errors and convert sprintfs.

From: Ben Whitten <[email protected]>

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.

---
Changes for v2:
- Replaced single string uses of sprintf with strcpy
- Detected more occurrences of potential errors.

 arch/mips/mach-au1x00/au1x00_eth.c          |  2 +-
 arch/powerpc/cpu/mpc8260/ether_scc.c        |  2 +-
 arch/powerpc/cpu/mpc8xx/fec.c               |  2 +-
 arch/powerpc/cpu/mpc8xx/scc.c               |  2 +-
 arch/powerpc/cpu/mpc8xx/video.c             |  4 ++--
 board/freescale/b4860qds/eth_b4860qds.c     |  8 ++++----
 board/freescale/corenet_ds/eth_hydra.c      |  2 +-
 board/freescale/corenet_ds/eth_superhydra.c |  2 +-
 board/freescale/ls1021aqds/eth.c            |  2 +-
 board/freescale/ls1043aqds/eth.c            |  2 +-
 board/freescale/ls2080aqds/eth.c            |  2 +-
 board/freescale/t102xqds/eth_t102xqds.c     |  2 +-
 board/freescale/t1040qds/eth.c              |  2 +-
 board/freescale/t208xqds/eth_t208xqds.c     |  2 +-
 board/freescale/t4qds/eth.c                 |  2 +-
 board/gdsys/common/ihs_mdio.c               |  2 +-
 board/keymile/common/common.c               |  4 ++--
 board/mpl/common/common_util.c              |  8 ++++----
 board/samsung/universal_c210/universal.c    |  4 ++--
 board/siemens/rut/board.c                   |  2 +-
 board/vscom/baltos/board.c                  |  2 +-
 common/cmd_elf.c                            | 13 ++++++++-----
 common/cmd_mtdparts.c                       |  2 +-
 common/cmd_nvedit.c                         |  2 +-
 disk/part_dos.c                             |  4 ++--
 disk/part_efi.c                             |  2 +-
 disk/part_iso.c                             |  2 +-
 drivers/block/sata_dwc.c                    |  4 ++--
 drivers/net/altera_tse.c                    |  2 +-
 drivers/net/at91_emac.c                     |  2 +-
 drivers/net/ax88180.c                       |  2 +-
 drivers/net/cpsw.c                          |  2 +-
 drivers/net/davinci_emac.c                  |  2 +-
 drivers/net/designware.c                    |  2 +-
 drivers/net/dm9000x.c                       |  2 +-
 drivers/net/fm/memac_phy.c                  |  2 +-
 drivers/net/fm/tgec_phy.c                   |  2 +-
 drivers/net/fsl_mdio.c                      |  2 +-
 drivers/net/ftgmac100.c                     |  2 +-
 drivers/net/ftmac100.c                      |  2 +-
 drivers/net/greth.c                         |  4 ++--
 drivers/net/keystone_net.c                  |  2 +-
 drivers/net/ldpaa_eth/ldpaa_eth.c           |  4 ++--
 drivers/net/lpc32xx_eth.c                   |  2 +-
 drivers/net/mpc512x_fec.c                   |  2 +-
 drivers/net/mpc5xxx_fec.c                   |  2 +-
 drivers/net/mvgbe.c                         |  2 +-
 drivers/net/ne2000_base.c                   |  2 +-
 drivers/net/pch_gbe.c                       |  2 +-
 drivers/net/sh_eth.c                        |  2 +-
 drivers/net/tsec.c                          |  2 +-
 drivers/usb/gadget/f_fastboot.c             |  6 +++---
 include/configs/tam3517-common.h            |  2 +-
 scripts/kconfig/mconf.c                     |  2 +-
 54 files changed, 76 insertions(+), 73 deletions(-)
arch/mips/mach-au1x00/au1x00_eth.c +1 -1
index d6ebe07..3f9f91e 100644
@@ -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;
arch/powerpc/cpu/mpc8260/ether_scc.c +1 -1
index 5ba8bed..fff8f2b 100644
@@ -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;
arch/powerpc/cpu/mpc8xx/fec.c +1 -1
index 2e19603..ea4ab3a 100644
@@ -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);
arch/powerpc/cpu/mpc8xx/scc.c +1 -1
index 5498440..3474637 100644
@@ -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;
arch/powerpc/cpu/mpc8xx/video.c +2 -2
index 15cee3f..c35406d 100644
@@ -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, wd at denx.de");
+	strcpy(info, "    Wolfgang DENK, wd at denx.de");
 	video_drawstring (VIDEO_INFO_X, VIDEO_INFO_Y + VIDEO_FONT_HEIGHT * 2,
 					info);
 
board/freescale/b4860qds/eth_b4860qds.c +4 -4
index df90476..4b2303e 100644
@@ -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:
board/freescale/corenet_ds/eth_hydra.c +1 -1
index 172a55b..55437e8 100644
@@ -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);
 
board/freescale/corenet_ds/eth_superhydra.c +1 -1
index 62b1635..3f11f5f 100644
@@ -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);
 
board/freescale/ls1021aqds/eth.c +1 -1
index be351be..bf3e08a 100644
@@ -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);
 
board/freescale/ls1043aqds/eth.c +1 -1
index b7fc360..88b10a0 100644
@@ -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);
 
board/freescale/ls2080aqds/eth.c +1 -1
index 0637ecf..ebc9d47 100644
@@ -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);
 
board/freescale/t102xqds/eth_t102xqds.c +1 -1
index 99c23f7..ca54e2a 100644
@@ -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);
 
board/freescale/t1040qds/eth.c +1 -1
index 8bf34fa..872e6e8 100644
@@ -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);
 
board/freescale/t208xqds/eth_t208xqds.c +1 -1
index 1c0ce24..f08cff2 100644
@@ -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);
 
board/freescale/t4qds/eth.c +1 -1
index 2dfdcbb..83a3a9b 100644
@@ -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);
 
board/gdsys/common/ihs_mdio.c +1 -1
index 1d6eb7b..262ead5 100644
@@ -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;
 
board/keymile/common/common.c +2 -2
index 8de129d..a42f3ec 100644
@@ -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);
 
@@ -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");
board/mpl/common/common_util.c +4 -4
index 6b96bd5..2262175 100644
@@ -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 {
@@ -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;
@@ -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;
     }
board/samsung/universal_c210/universal.c +2 -2
index c25b486..426ae14 100644
@@ -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();
board/siemens/rut/board.c +1 -1
index f94e3e5..b3c666c 100644
@@ -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)
board/vscom/baltos/board.c +1 -1
index 638d14f..ac44e32 100644
@@ -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) {
common/cmd_elf.c +8 -5
index 86e694a..5190cc6 100644
@@ -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");
@@ -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));
common/cmd_mtdparts.c +1 -1
index 422c069..dab1958 100644
@@ -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) {
common/cmd_nvedit.c +1 -1
index 2f9cdd0..9caf535 100644
@@ -595,7 +595,7 @@ static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc,
 	/* Set read buffer to initial value or empty sting */
 	init_val = getenv(argv[1]);
 	if (init_val)
-		sprintf(buffer, "%s", init_val);
+		strcpy(buffer, init_val);
 	else
 		buffer[0] = '\0';
 
disk/part_dos.c +2 -2
index 89263d3..924383e 100644
@@ -231,7 +231,7 @@ static int get_partition_info_extended (block_dev_desc_t *dev_desc, int ext_part
 					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);
@@ -266,7 +266,7 @@ static int get_partition_info_extended (block_dev_desc_t *dev_desc, int ext_part
 		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
disk/part_efi.c +1 -1
index b1e0155..efb6d96 100644
@@ -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,
disk/part_iso.c +1 -1
index 2547c70..4050963 100644
@@ -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:
drivers/block/sata_dwc.c +2 -2
index 9e8b067..b14985a 100644
@@ -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 "
@@ -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;
drivers/net/altera_tse.c +1 -1
index 3eaa270..92a1b64 100644
@@ -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;
 
drivers/net/at91_emac.c +1 -1
index d51e098..2659592 100644
@@ -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;
drivers/net/ax88180.c +1 -1
index ded9e06..43a67a5 100644
@@ -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;
drivers/net/cpsw.c +1 -1
index 3dff9df..7104754 100644
@@ -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);
 }
drivers/net/davinci_emac.c +1 -1
index 0444795..92c3dca 100644
@@ -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;
drivers/net/designware.c +1 -1
index 04114a1..5936198 100644
@@ -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;
 
drivers/net/dm9000x.c +1 -1
index 3c41cec..93c6667 100644
@@ -630,7 +630,7 @@ int dm9000_initialize(bd_t *bis)
 	dev->halt = dm9000_halt;
 	dev->send = dm9000_send;
 	dev->recv = dm9000_rx;
-	sprintf(dev->name, "dm9000");
+	strcpy(dev->name, "dm9000");
 
 	eth_register(dev);
 
drivers/net/fm/memac_phy.c +1 -1
index 4ab78e6..5079342 100644
@@ -146,7 +146,7 @@ int fm_memac_mdio_init(bd_t *bis, struct memac_mdio_info *info)
 	bus->read = memac_mdio_read;
 	bus->write = memac_mdio_write;
 	bus->reset = memac_mdio_reset;
-	sprintf(bus->name, info->name);
+	strcpy(bus->name, info->name);
 
 	bus->priv = info->regs;
 
drivers/net/fm/tgec_phy.c +1 -1
index 24cb17b..f038541 100644
@@ -118,7 +118,7 @@ int fm_tgec_mdio_init(bd_t *bis, struct tgec_mdio_info *info)
 	bus->read = tgec_mdio_read;
 	bus->write = tgec_mdio_write;
 	bus->reset = tgec_mdio_reset;
-	sprintf(bus->name, info->name);
+	strcpy(bus->name, info->name);
 
 	bus->priv = info->regs;
 
drivers/net/fsl_mdio.c +1 -1
index d6b181b..f48bbc3 100644
@@ -104,7 +104,7 @@ int fsl_pq_mdio_init(bd_t *bis, struct fsl_pq_mdio_info *info)
 	bus->read = tsec_phy_read;
 	bus->write = tsec_phy_write;
 	bus->reset = fsl_pq_mdio_reset;
-	sprintf(bus->name, info->name);
+	strcpy(bus->name, info->name);
 
 	bus->priv = (void *)info->regs;
 
drivers/net/ftgmac100.c +1 -1
index 515f0b2..5ccc4be 100644
@@ -562,7 +562,7 @@ int ftgmac100_initialize(bd_t *bd)
 	memset(dev, 0, sizeof(*dev));
 	memset(priv, 0, sizeof(*priv));
 
-	sprintf(dev->name, "FTGMAC100");
+	strcpy(dev->name, "FTGMAC100");
 	dev->iobase	= CONFIG_FTGMAC100_BASE;
 	dev->init	= ftgmac100_init;
 	dev->halt	= ftgmac100_halt;
drivers/net/ftmac100.c +1 -1
index bd94f83..1fc7da9 100644
@@ -246,7 +246,7 @@ int ftmac100_initialize (bd_t *bd)
 	memset (dev, 0, sizeof (*dev));
 	memset (priv, 0, sizeof (*priv));
 
-	sprintf (dev->name, "FTMAC100");
+	strcpy(dev->name, "FTMAC100");
 	dev->iobase	= CONFIG_FTMAC100_BASE;
 	dev->init	= ftmac100_init;
 	dev->halt	= ftmac100_halt;
drivers/net/greth.c +2 -2
index 088cb22..aa5d711 100644
@@ -640,9 +640,9 @@ int greth_initialize(bd_t * bis)
 
 	/* Make descriptor string */
 	if (greth->gbit_mac) {
-		sprintf(dev->name, "GRETH_10/100/GB");
+		strcpy(dev->name, "GRETH_10/100/GB");
 	} else {
-		sprintf(dev->name, "GRETH_10/100");
+		strcpy(dev->name, "GRETH_10/100");
 	}
 
 	/* initiate PHY, select speed/duplex depending on connected PHY */
drivers/net/keystone_net.c +1 -1
index 24ca52e..209fae9 100644
@@ -586,7 +586,7 @@ int keystone2_emac_initialize(struct eth_priv_t *eth_priv)
 		mdio_bus->write	= keystone2_mdio_write;
 		mdio_bus->reset	= keystone2_mdio_reset;
 		mdio_bus->priv	= (void *)EMAC_MDIO_BASE_ADDR;
-		sprintf(mdio_bus->name, "ethernet-mdio");
+		strcpy(mdio_bus->name, "ethernet-mdio");
 
 		res = mdio_register(mdio_bus);
 		if (res)
drivers/net/ldpaa_eth/ldpaa_eth.c +2 -2
index 69530b1..3857122 100644
@@ -628,11 +628,11 @@ static int ldpaa_dpmac_bind(struct ldpaa_eth_priv *priv)
 #endif
 
 	memset(&dpmac_endpoint, 0, sizeof(struct dprc_endpoint));
-	sprintf(dpmac_endpoint.type, "dpmac");
+	strcpy(dpmac_endpoint.type, "dpmac");
 	dpmac_endpoint.id = priv->dpmac_id;
 
 	memset(&dpni_endpoint, 0, sizeof(struct dprc_endpoint));
-	sprintf(dpni_endpoint.type, "dpni");
+	strcpy(dpni_endpoint.type, "dpni");
 	dpni_endpoint.id = dflt_dpni->dpni_id;
 
 	err = dprc_connect(dflt_mc_io, MC_CMD_NO_FLAGS,
drivers/net/lpc32xx_eth.c +1 -1
index e76e9bc..972e860 100644
@@ -582,7 +582,7 @@ int lpc32xx_eth_phylib_init(struct eth_device *dev, int phyid)
 	}
 	bus->read = lpc32xx_eth_phy_read;
 	bus->write = lpc32xx_eth_phy_write;
-	sprintf(bus->name, dev->name);
+	strcpy(bus->name, dev->name);
 
 	ret = mdio_register(bus);
 	if (ret) {
drivers/net/mpc512x_fec.c +1 -1
index 22ea114..e850672 100644
@@ -635,7 +635,7 @@ int mpc512x_fec_initialize (bd_t * bis)
 	dev->send = mpc512x_fec_send;
 	dev->recv = mpc512x_fec_recv;
 
-	sprintf (dev->name, "FEC");
+	strcpy(dev->name, "FEC");
 	eth_register (dev);
 
 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
drivers/net/mpc5xxx_fec.c +1 -1
index 2ebd176..e13b4cf 100644
@@ -913,7 +913,7 @@ int mpc5xxx_fec_initialize(bd_t * bis)
 	dev->send = mpc5xxx_fec_send;
 	dev->recv = mpc5xxx_fec_recv;
 
-	sprintf(dev->name, "FEC");
+	strcpy(dev->name, "FEC");
 	eth_register(dev);
 
 #if defined(CONFIG_MII) || defined(CONFIG_CMD_MII)
drivers/net/mvgbe.c +1 -1
index ab5aa68..b16be92 100644
@@ -675,7 +675,7 @@ int mvgbe_phylib_init(struct eth_device *dev, int phyid)
 	}
 	bus->read = mvgbe_phy_read;
 	bus->write = mvgbe_phy_write;
-	sprintf(bus->name, dev->name);
+	strcpy(bus->name, dev->name);
 
 	ret = mdio_register(bus);
 	if (ret) {
drivers/net/ne2000_base.c +1 -1
index 07a7cec..887cfd9 100644
@@ -794,7 +794,7 @@ int ne2k_register(void)
 	dev->send = ne2k_send;
 	dev->recv = ne2k_recv;
 
-	sprintf(dev->name, "NE2000");
+	strcpy(dev->name, "NE2000");
 
 	return eth_register(dev);
 }
drivers/net/pch_gbe.c +1 -1
index dfc0100..6bae11e 100644
@@ -386,7 +386,7 @@ static int pch_gbe_mdio_init(const char *name, struct pch_gbe_regs *mac_regs)
 
 	bus->read = pch_gbe_mdio_read;
 	bus->write = pch_gbe_mdio_write;
-	sprintf(bus->name, name);
+	strcpy(bus->name, name);
 
 	bus->priv = (void *)mac_regs;
 
drivers/net/sh_eth.c +1 -1
index a320b4d..443a4da 100644
@@ -560,7 +560,7 @@ int sh_eth_initialize(bd_t *bd)
 	dev->recv = sh_eth_recv;
 	eth->port_info[eth->port].dev = dev;
 
-	sprintf(dev->name, SHETHER_NAME);
+	strcpy(dev->name, SHETHER_NAME);
 
 	/* Register Device to EtherNet subsystem  */
 	eth_register(dev);
drivers/net/tsec.c +1 -1
index 4bdc188..9b09caf 100644
@@ -632,7 +632,7 @@ static int tsec_initialize(bd_t *bis, struct tsec_info_struct *tsec_info)
 	priv->phyaddr = tsec_info->phyaddr;
 	priv->flags = tsec_info->flags;
 
-	sprintf(dev->name, tsec_info->devname);
+	strcpy(dev->name, tsec_info->devname);
 	priv->interface = tsec_info->interface;
 	priv->bus = miiphy_get_dev_by_name(tsec_info->mii_devname);
 	dev->iobase = 0;
drivers/usb/gadget/f_fastboot.c +3 -3
index 20b6c18..87e54eb 100644
@@ -477,7 +477,7 @@ static void rx_handler_dl_image(struct usb_ep *ep, struct usb_request *req)
 		req->complete = rx_handler_command;
 		req->length = EP_BUFFER_SIZE;
 
-		sprintf(response, "OKAY");
+		strcpy(response, "OKAY");
 		fastboot_tx_write_str(response);
 
 		printf("\ndownloading of %d bytes finished\n", download_bytes);
@@ -506,10 +506,10 @@ static void cb_download(struct usb_ep *ep, struct usb_request *req)
 	printf("Starting download of %d bytes\n", download_size);
 
 	if (0 == download_size) {
-		sprintf(response, "FAILdata invalid size");
+		strcpy(response, "FAILdata invalid size");
 	} else if (download_size > CONFIG_FASTBOOT_BUF_SIZE) {
 		download_size = 0;
-		sprintf(response, "FAILdata too large");
+		strcpy(response, "FAILdata too large");
 	} else {
 		sprintf(response, "DATA%08x", download_size);
 		req->complete = rx_handler_dl_image;
include/configs/tam3517-common.h +1 -1
index ec0a812..2d941ca 100644
@@ -384,7 +384,7 @@ do {								\
 		if (i)						\
 			sprintf(ethname, "eth%daddr", i);	\
 		else						\
-			sprintf(ethname, "ethaddr");		\
+			strcpy(ethname, "ethaddr");		\
 		printf("Setting %s from EEPROM with %s\n", ethname, buf);\
 		setenv(ethname, buf);				\
 	}							\
scripts/kconfig/mconf.c +1 -1
index 315ce2c..953d5c7 100644
@@ -379,7 +379,7 @@ static void update_text(char *buf, size_t start, size_t end, void *_data)
 				data->targets[k] = pos->target;
 				k++;
 			} else {
-				sprintf(header, "   ");
+				strcpy(header, "   ");
 			}
 
 			memcpy(buf + pos->offset, header, sizeof(header) - 1);

--
2.6.4

#3 lore raw

PATCH v2 1/1 Fix GCC format-security errors and convert sprintfs.

Dear ben.whitten at gmail.com,

Quoted 5 lines · In message <[email protected]> you wrote:

From: Ben Whitten <[email protected]>

With format-security errors turned on, GCC picks up the use of sprintf with a format parameter not being a string literal.

Quoted 7 lines

Simple uses of sprintf are also converted to use strcpy.

---
Changes for v2:
- Replaced single string uses of sprintf with strcpy
- Detected more occurrences of potential errors.

Thanks!!

Best regards,

Wolfgang Denk

Signature · 7 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Ein weiser Herrscher kann in einem gro?en Land  mehr  Gutes  bewirken
als  in  einem kleinen - ein dummer Herrscher aber auch viel mehr Un-
fug. Da weise Herrscher seltener sind als dumme, war ich schon  immer
gegen gro?e Reiche skeptisch.                   - Herbert Rosendorfer
#4 lore raw

PATCH v2 1/1 Fix GCC format-security errors and convert sprintfs.

In reply to ben.whitten at gmail.com
Quoted 8 lines · ben.whitten at gmail.com

From: Ben Whitten <[email protected]>

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.

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160114/a8e2fec7/attachment.sig>
#5 lore raw

PATCH v2 1/1 Fix GCC format-security errors and convert sprintfs.

In reply to ben.whitten at gmail.com
Quoted 10 lines · Ben Whitten

From: Ben Whitten <[email protected]>

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.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20160115/acd77ab3/attachment.sig>