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

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