Skip to contentSkip to conversation

parport: Use kstrdup() in parse_data()

PATCH New Thorsten Blum 1 participant 1 message Nov 18 Parallel port

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 parport: Use kstrdup() in parse_data()

strcpy() has been deprecated [1] because it performs no bounds checking on the destination buffer, which can lead to buffer overflows.

While the current code works correctly, replace kmalloc() and strcpy() with a single kstrdup() call to simplify the code.

---
Andrew, this hasn't received any feedback since April. Could you maybe pick it up? Thanks.

Changes in v2:
- Reword subject and commit description
- No code changes
- v1: https://lore.kernel.org/r/[email protected]/

 drivers/parport/probe.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/parport/probe.c +1 -2
index 5d1b9aacb130..bf9d81c0abaf 100644
@@ -52,7 +52,7 @@ static void pretty_print(struct parport *port, int device)
 
 static void parse_data(struct parport *port, int device, char *str)
 {
-	char *txt = kmalloc(strlen(str)+1, GFP_KERNEL);
+	char *txt = kstrdup(str, GFP_KERNEL);
 	char *p = txt, *q;
 	int guessed_class = PARPORT_CLASS_UNSPEC;
 	struct parport_device_info *info = &port->probe_info[device + 1];
@@ -61,7 +61,6 @@ static void parse_data(struct parport *port, int device, char *str)
 		pr_warn("%s probe: memory squeeze\n", port->name);
 		return;
 	}
-	strcpy(txt, str);
 	while (p) {
 		char *sep;
 		q = strchr(p, ';');