Skip to contentSkip to conversation

clean up missing overflow check in get_blkdev_list

PATCH In review Neil Horman 2 participants 2 messages Aug 16, 2005 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clean up missing overflow check in get_blkdev_list

Patch to clean up missing overflow check in get_blkdev_list. the printf which adds the "Block Devices" string in /proc/devices can overflow the presented page if get_chrdev_list eats up the entire 4k space. Tested by myself, with good results.

 genhd.c |    2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)
drivers/block/genhd.c renamed from drivers/block/genhd.c.orig +1 -1
@@ -45,7 +45,7 @@ int get_blkdev_list(char *p, int used)
 	struct blk_major_name *n;
 	int i, len;
 
-	len = sprintf(p, "\nBlock devices:\n");
+	len = snprintf(p, (PAGE_SIZE-used), "\nBlock devices:\n");
 
 	down(&block_subsys_sem);
 	for (i = 0; i < ARRAY_SIZE(major_names); i++) {
Signature · 8 lines
/***************************************************
 *Neil Horman
 *Software Engineer
 *Red Hat, Inc.
 *[email protected]
 *gpg keyid: 1024D / 0x92A74FA1
 *http://pgp.mit.edu
 ***************************************************/
#1 lore raw
Quoted 4 lines · Neil Horman

Patch to clean up missing overflow check in get_blkdev_list. the printf which adds the "Block Devices" string in /proc/devices can overflow the presented page if get_chrdev_list eats up the entire 4k space. Tested by myself, with good results.

Please switch /proc/device over to the proper seq_file model instead.