Skip to contentSkip to conversation

Staging: dgnc: Replace snprintf instead of sprintf

PATCH In review DHANAPAL, GNANACHANDRAN (G.) 2 participants 2 messages Apr 24, 2015 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Staging: dgnc: Replace snprintf instead of sprintf

This patch replaces snprintf instead of sprintf to avoid buffer overflow

---
 drivers/staging/dgnc/dgnc_mgmt.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/dgnc/dgnc_mgmt.c +1 -1
index b13318a..aa20a66 100644
@@ -116,7 +116,7 @@ long dgnc_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 		spin_lock_irqsave(&dgnc_global_lock, flags);
 
 		ddi.dinfo_nboards = dgnc_NumBoards;
-		sprintf(ddi.dinfo_version, "%s", DG_PART);
+		snprintf(ddi.dinfo_version, strlen(DG_PART)+1, "%s", DG_PART);
 
 		spin_unlock_irqrestore(&dgnc_global_lock, flags);
 
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 12 lines · GNANACHANDRAN (G.)

This patch replaces snprintf instead of sprintf to avoid buffer overflow

---
 drivers/staging/dgnc/dgnc_mgmt.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/dgnc/dgnc_mgmt.c +0 -0
index b13318a..aa20a66 100644

drivers/staging/dgnc/dgnc_mgmt.c long dgnc_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg) · line 119

Quoted 5 lines
drivers/staging/dgnc/dgnc_mgmt.c +1 -1
@@ -116,7 +116,7 @@ long dgnc_mgmt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 		spin_lock_irqsave(&dgnc_global_lock, flags);
 
 		ddi.dinfo_nboards = dgnc_NumBoards;
-		sprintf(ddi.dinfo_version, "%s", DG_PART);
+		snprintf(ddi.dinfo_version, strlen(DG_PART)+1, "%s", DG_PART);

This change makes no sense. If the original had memory corruption then the new code has memory corruption as well.

regards,
dan carpenter