Thread (5 messages) 5 messages, 3 authors, 2011-02-13

Re: [PATCH] md: Remove risk of overflow via sprintf) by using snprintf() in md_check_recovery()

From: Daniel K. <hidden>
Date: 2011-02-12 09:38:54
Also in: lkml

Jesper Juhl wrote:
sprintf() is dangerous - given the wrong source string it will overflow the destination. snprintf() is safer in that at least we'll never overflow the destination. Even if overflow will never happen today, code changes over time and snprintf() is just safer in the long run.
quoted hunk ↗ jump to hunk
-						sprintf(nm,"rd%d", rdev->raid_disk);
+						snprintf(nm, sizeof(nm), "rd%d", rdev->raid_disk);
 						sysfs_remove_link(&mddev->kobj, nm);
What if "rd1234" get truncated to "rd123" and you remove the wrong link.
(No, I didn't actually bother to check how much room was allocated.)

Isn't it better to overflow than silently to unlink the wrong file?

What will happen when you try to unlink the "rd123" file again, when the actual 123 is meant?

Whatever the real fix is, should this be checked for at create_link time as well?


Daniel K.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help