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