From 7bb5221b1f943c53c9abb96f7a25ef922ae9972d Mon Sep 17 00:00:00 2001 From: Isaac Dunham Date: Fri, 28 Jun 2013 02:11:48 -0500 Subject: modinfo: support -b basedir and -k kernel.release, fix two bugs Add two less-frequently used flags for modinfo; -b specifies an alternate root and -k replaces the output of uname -r. Additionally, avoid a potential overflow in sprintf, and correct an inverted test. --- toys/other/modinfo.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'toys') diff --git a/toys/other/modinfo.c b/toys/other/modinfo.c index 3548247d..33140370 100644 --- a/toys/other/modinfo.c +++ b/toys/other/modinfo.c @@ -2,13 +2,15 @@ * * Copyright 2012 Andre Renaud -USE_MODINFO(NEWTOY(modinfo, "<1F:0", TOYFLAG_BIN)) +USE_MODINFO(NEWTOY(modinfo, "<1b:k:F:0", TOYFLAG_BIN)) config MODINFO bool "modinfo" default y help - usage: modinfo [-0] [-F field] [modulename...] + usage: modinfo [-0] [-b basedir] [-k kernrelease] [-F field] [modulename...] + Display module fields for all specified modules, looking in + /lib/modules// (kernrelease defaults to uname -r). */ #define FOR_modinfo @@ -16,6 +18,8 @@ config MODINFO GLOBALS( char *field; + char *knam; + char *base; long mod; ) @@ -23,7 +27,7 @@ GLOBALS( static void output_field(char *field, char *value) { if (!TT.field) xprintf("%s:%*c", field, 15 - strlen(field), ' '); - else if (!strcmp(TT.field, field)) return; + else if (strcmp(TT.field, field)) return; xprintf("%s", value); xputc((toys.optflags & FLAG_0) ? 0 : '\n'); } @@ -100,7 +104,10 @@ void modinfo_main(void) struct utsname uts; if (uname(&uts) < 0) perror_exit("bad uname"); - sprintf(toybuf, "/lib/modules/%s", uts.release); + if (snprintf(toybuf, sizeof(toybuf), "%s/lib/modules/%s", + (toys.optflags & FLAG_b) ? TT.base : "", + (toys.optflags & FLAG_k) ? TT.knam : uts.release) >= sizeof(toybuf)) + perror_exit("basedir/kernrelease too long"); dirtree_read(toybuf, check_module); } } -- cgit v1.2.3