Skip to contentSkip to conversation

um,ethertap: use strncpy

PATCH RESEND In review Alan 2 participants 2 messages Jan 20, 2015 User-mode Linux (UML)

lore
Share & tools
lore

Alan

author
#0 lore raw

PATCH RESEND 1/1 um,ethertap: use strncpy

I can't prove the case pointed out in
https://bugzilla.kernel.org/show_bug.cgi?id=82341
is correct so let us play safe.

---
 arch/um/os-Linux/drivers/ethertap_user.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/um/os-Linux/drivers/ethertap_user.c +1 -1
index b39b669..6d49182 100644
@@ -105,7 +105,7 @@ static int etap_tramp(char *dev, char *gate, int control_me,
 	sprintf(data_fd_buf, "%d", data_remote);
 	sprintf(version_buf, "%d", UML_NET_VERSION);
 	if (gate != NULL) {
-		strcpy(gate_buf, gate);
+		strncpy(gate_buf, gate, 15);
 		args = setup_args;
 	}
 	else args = nosetup_args;
#1 lore raw
Quoted 14 lines · Alan

I can't prove the case pointed out in
https://bugzilla.kernel.org/show_bug.cgi?id=82341
is correct so let us play safe.

---
 arch/um/os-Linux/drivers/ethertap_user.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/um/os-Linux/drivers/ethertap_user.c +0 -0
index b39b669..6d49182 100644

arch/um/os-Linux/drivers/ethertap_user.c static int etap_tramp(char *dev, char *gate, int control_me, · line 106

Quoted 2 lines
arch/um/os-Linux/drivers/ethertap_user.c +0 -0
@@ -105,7 +105,7 @@ static int etap_tramp(char *dev, char *gate, int control_me,
        sprintf(data_fd_buf, "%d", data_remote);
        sprintf(version_buf, "%d", UML_NET_VERSION);

The two above may also overflow, if the numbers contain more than 5 resp. 6 digits.

arch/um/os-Linux/drivers/ethertap_user.c static int etap_tramp(char *dev, char *gate, int control_me, · line 108

Quoted 3 lines
arch/um/os-Linux/drivers/ethertap_user.c +1 -1
        if (gate != NULL) {
-               strcpy(gate_buf, gate);
+               strncpy(gate_buf, gate, 15);

Same comment as before:

"This will copy at most 15 bytes.
If "gate" contains 15 or more characters, gate_buf[] won't be zero-terminated.
I think you better use strlcpy(), unless the remaining of the buffer must be filled with zeroes."

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds