[klibc] [PATCH] fstype: fix possible null deref in check_for_modules()

maximilian attems max at stro.at
Thu Aug 4 14:24:36 PDT 2011


Make check_for_modules() more readable, just allways call
continue on NULL return. That way the possible null dereference
in strlen is no longer possible.

This doesn't yet make it unsuck, but is a small step.
Seen fixed too in blkid there with patch adding ko.gz support.

Cc: Karel Zak <kzak at redhat.com>
Signed-off-by: maximilian attems <max at stro.at>
---
 usr/kinit/fstype/fstype.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/usr/kinit/fstype/fstype.c b/usr/kinit/fstype/fstype.c
index 2e26c9a..c5a1432 100644
--- a/usr/kinit/fstype/fstype.c
+++ b/usr/kinit/fstype/fstype.c
@@ -171,13 +171,13 @@ static int check_for_modules(const char *fs_name)
 		return 0;
 	while (fgets(buf, sizeof(buf), f)) {
 		cp = strchr(buf, ':');
-		if (cp != NULL)
-			*cp = 0;
-		else
+		if (cp == NULL)
 			continue;
+		*cp = 0;
 		cp = strrchr(buf, '/');
-		if (cp != NULL)
-			cp++;
+		if (cp == NULL)
+			continue;
+		cp++;
 		i = strlen(cp);
 		if (i > 3) {
 			t = cp + i - 3;
-- 
1.7.5.4



More information about the klibc mailing list