Skip to contentSkip to conversation

siemens: avoid out of bound access

PATCH New Heinrich Schuchardt 4 participants 4 messages Aug 22, 2019 – Sep 2, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 siemens: avoid out of bound access

	char num[1];
	sprintf(num, "%d", i);

leads to a buffer overrun.

Simplify the overly complex coding.

---
 board/siemens/common/board.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
board/siemens/common/board.c +1 -4
index 676935a843..75462d1c34 100644
@@ -189,14 +189,11 @@ void set_env_gpios(unsigned char state)
 {
 	char *ptr_env;
 	char str_tmp[5];	/* must contain "ledX"*/
-	char num[1];
 	unsigned char i, idx, pos1, pos2, ccount;
 	unsigned char gpio_n, gpio_s0, gpio_s1;
 
 	for (i = 0; i < MAX_NR_LEDS; i++) {
-		strcpy(str_tmp, "led");
-		sprintf(num, "%d", i);
-		strcat(str_tmp, num);
+		sprintf(str_tmp, "led%d", i);
 
 		/* If env var is not found we stop */
 		ptr_env = env_get(str_tmp);

--
2.20.1

#2 lore raw

PATCH 1/1 siemens: avoid out of bound access

In reply to Heinrich Schuchardt

Hello Heinrich,

Am 22.08.2019 um 21:58 schrieb Heinrich Schuchardt:

Quoted 11 lines
	char num[1];
	sprintf(num, "%d", i);

leads to a buffer overrun.

Simplify the overly complex coding.

---
  board/siemens/common/board.c | 5 +----
  1 file changed, 1 insertion(+), 4 deletions(-)

Thanks!

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
#3 lore raw

PATCH 1/1 siemens: avoid out of bound access

In reply to Heinrich Schuchardt
Quoted 10 lines · Heinrich Schuchardt
char num[1];
	sprintf(num, "%d", i);

leads to a buffer overrun.

Simplify the overly complex coding.

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: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190902/b7dd7f35/attachment.sig>