Blame SOURCES/kmod-0003-libkmod-Handle-long-lines-in-proc-modules.patch

ca9082
From 22dadafa9fa961fa70cc616679b8b24689382348 Mon Sep 17 00:00:00 2001
ca9082
From: Tony Camuso <tcamuso@redhat.com>
ca9082
Date: Fri, 24 Jun 2016 12:38:52 -0400
ca9082
Subject: [RHEL-7.3 PATCH 3/3] libkmod: Handle long lines in /proc/modules
ca9082
ca9082
Cherry-picked without conflicts from the following upstream commit.
ca9082
ca9082
commit 2206d7f763a1c9cf88f77d0ab19e410d17749361
ca9082
Author: Michal Marek <mmarek@suse.cz>
ca9082
Date:   Fri Jun 17 16:04:15 2016 +0200
ca9082
ca9082
    libkmod: Handle long lines in /proc/modules
ca9082
ca9082
    kmod_module_new_from_loaded() calls fgets with a 4k buffer. When a
ca9082
    module such as usbcore is used by too many modules, the rest of the line
ca9082
    is considered a beginning of another lines and we eventually get errors
ca9082
    like these from lsmod:
ca9082
ca9082
    libkmod: kmod_module_get_holders: could not open '/sys/module/100,/holders': No such file or directory
ca9082
ca9082
    together with bogus entries in the output. In kmod_module_get_size, the
ca9082
    problem does not affect functionality, but the line numbers in error
ca9082
    messages will be wrong.
ca9082
ca9082
    Signed-off-by: Michal Marek <mmarek@suse.com>
ca9082
ca9082
Signed-off-by: Tony Camuso <tcamuso@redhat.com>
ca9082
---
ca9082
 libkmod/libkmod-module.c | 12 ++++++++++--
ca9082
 1 file changed, 10 insertions(+), 2 deletions(-)
ca9082
ca9082
diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c
ca9082
index 366308f..47bb880 100644
ca9082
--- a/libkmod/libkmod-module.c
ca9082
+++ b/libkmod/libkmod-module.c
ca9082
@@ -1660,13 +1660,14 @@ KMOD_EXPORT int kmod_module_new_from_loaded(struct kmod_ctx *ctx,
ca9082
 		struct kmod_module *m;
ca9082
 		struct kmod_list *node;
ca9082
 		int err;
ca9082
+		size_t len = strlen(line);
ca9082
 		char *saveptr, *name = strtok_r(line, " \t", &saveptr);
ca9082
 
ca9082
 		err = kmod_module_new_from_name(ctx, name, &m);
ca9082
 		if (err < 0) {
ca9082
 			ERR(ctx, "could not get module from name '%s': %s\n",
ca9082
 				name, strerror(-err));
ca9082
-			continue;
ca9082
+			goto eat_line;
ca9082
 		}
ca9082
 
ca9082
 		node = kmod_list_append(l, m);
ca9082
@@ -1676,6 +1677,9 @@ KMOD_EXPORT int kmod_module_new_from_loaded(struct kmod_ctx *ctx,
ca9082
 			ERR(ctx, "out of memory\n");
ca9082
 			kmod_module_unref(m);
ca9082
 		}
ca9082
+eat_line:
ca9082
+		while (line[len - 1] != '\n' && fgets(line, sizeof(line), fp))
ca9082
+			len = strlen(line);
ca9082
 	}
ca9082
 
ca9082
 	fclose(fp);
ca9082
@@ -1825,12 +1829,13 @@ KMOD_EXPORT long kmod_module_get_size(const struct kmod_module *mod)
ca9082
 	}
ca9082
 
ca9082
 	while (fgets(line, sizeof(line), fp)) {
ca9082
+		size_t len = strlen(line);
ca9082
 		char *saveptr, *endptr, *tok = strtok_r(line, " \t", &saveptr);
ca9082
 		long value;
ca9082
 
ca9082
 		lineno++;
ca9082
 		if (tok == NULL || !streq(tok, mod->name))
ca9082
-			continue;
ca9082
+			goto eat_line;
ca9082
 
ca9082
 		tok = strtok_r(NULL, " \t", &saveptr);
ca9082
 		if (tok == NULL) {
ca9082
@@ -1848,6 +1853,9 @@ KMOD_EXPORT long kmod_module_get_size(const struct kmod_module *mod)
ca9082
 
ca9082
 		size = value;
ca9082
 		break;
ca9082
+eat_line:
ca9082
+		while (line[len - 1] != '\n' && fgets(line, sizeof(line), fp))
ca9082
+			len = strlen(line);
ca9082
 	}
ca9082
 	fclose(fp);
ca9082
 
ca9082
-- 
ca9082
1.8.3.1
ca9082