[klibc] [PATCH 2/7] kinit: try_name() check snprintf return
maximilian attems
max at stro.at
Tue Jul 5 11:06:27 PDT 2011
Signed-off-by: maximilian attems <max at stro.at>
---
usr/kinit/name_to_dev.c | 8 ++++++--
1 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/usr/kinit/name_to_dev.c b/usr/kinit/name_to_dev.c
index d491285..8604375 100644
--- a/usr/kinit/name_to_dev.c
+++ b/usr/kinit/name_to_dev.c
@@ -26,7 +26,9 @@ static dev_t try_name(char *name, int part)
int fd;
/* read device number from /sys/block/.../dev */
- snprintf(path, sizeof(path), "/sys/block/%s/dev", name);
+ len = snprintf(path, sizeof(path), "/sys/block/%s/dev", name);
+ if (len >= sizeof(path))
+ goto fail;
fd = open(path, 0, 0);
if (fd < 0)
goto fail;
@@ -49,7 +51,9 @@ static dev_t try_name(char *name, int part)
return res;
/* otherwise read range from .../range */
- snprintf(path, sizeof(path), "/sys/block/%s/range", name);
+ len = snprintf(path, sizeof(path), "/sys/block/%s/range", name);
+ if (len >= sizeof(path))
+ goto fail;
fd = open(path, 0, 0);
if (fd < 0)
goto fail;
--
1.7.5.4
More information about the klibc
mailing list