From 43204cb0bb13f6e81976cfb43dc0cfeb66a1e247 Mon Sep 17 00:00:00 2001 From: Alan Jenkins Date: Fri, 20 Feb 2009 13:50:56 +0000 Subject: [PATCH] modinfo: Fix failure with inaccessible current dir kerneltools bugzilla #6 Originally report refers to "sudo modinfo fglrx" on an NFS mount with root_sqaush. To reproduce: $ mkdir /tmp/noaccess $ cd /tmp/noaccess $ chmod a-x /tmp/noaccess $ /sbin/modinfo fglrx $ modinfo: could not open fglrx: Permission denied As suggested by Martin Pitt on Launchpad, the fix is to distinguish better between module names and filenames. If it contains "." or "/", it must be a filename. Otherwise, assume it is a module name. Users can still do "modinfo ./fglrx" if thats what they really want. Signed-off-by: Alan Jenkins --- modinfo.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/modinfo.c b/modinfo.c index 00ccef5..63c112f 100644 --- a/modinfo.c +++ b/modinfo.c @@ -279,15 +279,16 @@ static void *grab_module(const char *name, unsigned long *size, char**filename, struct utsname buf; char *depname, *p, *moddir; - data = grab_file(name, size); - if (data) { - *filename = strdup(name); - return data; - } - if (errno != ENOENT) { - fprintf(stderr, "modinfo: could not open %s: %s\n", - name, strerror(errno)); - return NULL; + if (strchr(name, '.') || strchr(name, '/')) { + data = grab_file(name, size); + if (data) { + *filename = strdup(name); + return data; + } else { + fprintf(stderr, "modinfo: could not open %s: %s\n", + name, strerror(errno)); + return NULL; + } } if (kernel) { -- 2.11.4.GIT