Bug fix for modules-2.1.8

Yuri A. Pudgorodsky (yur@jane.ecsc.mipt.ru)
Sun, 10 Nov 1996 21:00:20 +0300


Hello!

It seems to me, that the greatest and latest module utils
has a little typo.

Without the following patch, insmod try to allocate and zero bsssection
even if the module has zero size bss or has no bss section at all.
Results: insmod gets segmentation fault and a module been leaved in
the uninitialized state.

With the patch, almost seems to work fine for me :-)

Knock the wood?...

--- modules-2.1.8/insmod/load_elf.c~ Mon Nov 4 07:56:58 1996
+++ modules-2.1.8/insmod/load_elf.c Sun Nov 10 20:47:21 1996
@@ -366,7 +366,8 @@
}

/* JEJB: zero the bss (now it's actually allocated) */
- memset(secref[bss_seg], 0, bss_size);
+ if (bss_size)
+ memset(secref[bss_seg], 0, bss_size);

for (spnt = sections, i = 0; i < epnt->e_shnum; ++i, ++spnt) {
#ifdef __i386__
@@ -622,7 +623,9 @@
}

loaded = (char *)(((int)loaded + 3) & ~3);
- bss_size = loaded - secref[bss_seg];
+ /* yur: don't change bss_size if no bss in the module */
+ if (secref[bss_seg])
+ bss_size = loaded - secref[bss_seg];
progsize = codesize = loaded - textseg;
aout_flag = 0; /* i.e.: if it's not a.out, it _has_ to be ELF... */
if (defsym(strncmp, "_GLOBAL_OFFSET_TABLE_", loaded - textseg, N_BSS | N_EXT, TRANSIENT))