Re: [PATCH] libkmod: Handle long lines in /proc/modules
From: Lucas De Marchi <hidden>
Date: 2016-06-20 13:41:18
On Mon, Jun 20, 2016 at 10:16 AM, Michal Marek [off-list ref] wrote:
On 2016-06-20 14:55, Lucas De Marchi wrote:quoted
On Fri, Jun 17, 2016 at 11:04 AM, Michal Marek [off-list ref] wrote:quoted
Also, the buffer could be shrinked now, so that we do not use that much space on stack. Not sure if this is of interest or not. I left it as is.Yep, I think it's reasonable to be 64 bytes since it's the maximum length of a module nameOK. In kmod_module_get_size(), the buffer needs to be larger, though.quoted
quoted
diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index 1460c6746cc4..25dcda7667b7 100644 --- a/libkmod/libkmod-module.c +++ b/libkmod/libkmod-module.c@@ -1660,13 +1660,14 @@ KMOD_EXPORT int kmod_module_new_from_loaded(struct kmod_ctx *ctx, struct kmod_module *m; struct kmod_list *node; int err; + size_t len = strlen(line); char *saveptr, *name = strtok_r(line, " \t", &saveptr); err = kmod_module_new_from_name(ctx, name, &m); if (err < 0) { ERR(ctx, "could not get module from name '%s': %s\n", name, strerror(-err)); - continue; + goto eat_line;I think it would be better to "eat line" before anything else, above kmod_module_new_from_name(). So you don't need to change the flow here.Sure, but then we would need two buffers, because name is a pointer into line.
oh, right. Thinking again, I'm ok with your version. Lucas De Marchi