summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorMian Yousaf Kaukab <yousaf.kaukab@suse.com>2016-11-08 17:45:50 +0100
committerLucas De Marchi <lucas.demarchi@intel.com>2016-11-08 22:38:34 -0200
commit6b77f188969d72254f6bda291f4f2d9fd42f5ecc (patch)
treee0791bc21c4b8d930af1da3e27d0f544ce3ca685 /tools
parent965886b55ab2f80fc242c1bc7e92423c87424718 (diff)
downloadkmod-6b77f188969d72254f6bda291f4f2d9fd42f5ecc.tar.gz
kmod-6b77f188969d72254f6bda291f4f2d9fd42f5ecc.tar.bz2
kmod-6b77f188969d72254f6bda291f4f2d9fd42f5ecc.zip
depmod: ignore related modules in depmod_report_cycles
Only print actual cyclic dependencies. Print count of all the modules in cyclic dependency at the end of the function so that dependent modules which are not in cyclic chain can be ignored. Printing dependent modules which are not in cyclic chain causes buffer overflow as m->modnamesz is not included in buffer size calculations (loop == m is never true). This buffer overflow causes kmod to crash. Update depmod test to reflect the change as well. Reported-by: Andreas Färber <afaerber@suse.de> Signed-off-by: Mian Yousaf Kaukab <yousaf.kaukab@suse.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/depmod.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/tools/depmod.c b/tools/depmod.c
index ad01f66..f2b370f 100644
--- a/tools/depmod.c
+++ b/tools/depmod.c
@@ -1456,7 +1456,7 @@ static void depmod_report_cycles(struct depmod *depmod, uint16_t n_mods,
{
const char sep[] = " -> ";
int ir = 0;
- ERR("Found %u modules in dependency cycles!\n", n_roots);
+ int num_cyclic = 0;
while (n_roots > 0) {
int is, ie;
@@ -1491,6 +1491,7 @@ static void depmod_report_cycles(struct depmod *depmod, uint16_t n_mods,
if (m->visited) {
int i, n = 0, sz = 0;
char *buf;
+ bool is_cyclic = false;
for (i = ie - 1; i >= 0; i--) {
struct mod *loop = depmod->modules.array[edges[i]];
@@ -1498,9 +1499,17 @@ static void depmod_report_cycles(struct depmod *depmod, uint16_t n_mods,
n++;
if (loop == m) {
sz += loop->modnamesz - 1;
+ is_cyclic = true;
break;
}
}
+ /* Current module not found in dependency list.
+ * Must be a related module. Ignore it.
+ */
+ if (!is_cyclic)
+ continue;
+
+ num_cyclic += n;
buf = malloc(sz + n * strlen(sep) + 1);
sz = 0;
@@ -1538,6 +1547,8 @@ static void depmod_report_cycles(struct depmod *depmod, uint16_t n_mods,
}
}
}
+
+ ERR("Found %d modules in dependency cycles!\n", num_cyclic);
}
static int depmod_calculate_dependencies(struct depmod *depmod)