diff options
Diffstat (limited to 'modutils')
| -rw-r--r-- | modutils/insmod.c | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/modutils/insmod.c b/modutils/insmod.c index 9dcc5b02d..120feabf3 100644 --- a/modutils/insmod.c +++ b/modutils/insmod.c | |||
| @@ -2212,7 +2212,7 @@ static struct obj_section *obj_create_alloced_section(struct obj_file *f, | |||
| 2212 | sec->name = name; | 2212 | sec->name = name; |
| 2213 | sec->idx = newidx; | 2213 | sec->idx = newidx; |
| 2214 | if (size) | 2214 | if (size) |
| 2215 | sec->contents = xmalloc(size); | 2215 | sec->contents = xzalloc(size); |
| 2216 | 2216 | ||
| 2217 | obj_insert_section_load_order(f, sec); | 2217 | obj_insert_section_load_order(f, sec); |
| 2218 | 2218 | ||
| @@ -2227,7 +2227,7 @@ static struct obj_section *obj_create_alloced_section_first(struct obj_file *f, | |||
| 2227 | int newidx = f->header.e_shnum++; | 2227 | int newidx = f->header.e_shnum++; |
| 2228 | struct obj_section *sec; | 2228 | struct obj_section *sec; |
| 2229 | 2229 | ||
| 2230 | f->sections = xrealloc(f->sections, (newidx + 1) * sizeof(sec)); | 2230 | f->sections = xrealloc_vector(f->sections, 2, newidx); |
| 2231 | f->sections[newidx] = sec = arch_new_section(); | 2231 | f->sections[newidx] = sec = arch_new_section(); |
| 2232 | 2232 | ||
| 2233 | sec->header.sh_type = SHT_PROGBITS; | 2233 | sec->header.sh_type = SHT_PROGBITS; |
| @@ -2237,7 +2237,7 @@ static struct obj_section *obj_create_alloced_section_first(struct obj_file *f, | |||
| 2237 | sec->name = name; | 2237 | sec->name = name; |
| 2238 | sec->idx = newidx; | 2238 | sec->idx = newidx; |
| 2239 | if (size) | 2239 | if (size) |
| 2240 | sec->contents = xmalloc(size); | 2240 | sec->contents = xzalloc(size); |
| 2241 | 2241 | ||
| 2242 | sec->load_next = f->load_order; | 2242 | sec->load_next = f->load_order; |
| 2243 | f->load_order = sec; | 2243 | f->load_order = sec; |
| @@ -2689,8 +2689,7 @@ static void new_get_kernel_symbols(void) | |||
| 2689 | /* Collect the modules' symbols. */ | 2689 | /* Collect the modules' symbols. */ |
| 2690 | 2690 | ||
| 2691 | if (nmod) { | 2691 | if (nmod) { |
| 2692 | ext_modules = modules = xmalloc(nmod * sizeof(*modules)); | 2692 | ext_modules = modules = xzalloc(nmod * sizeof(*modules)); |
| 2693 | memset(modules, 0, nmod * sizeof(*modules)); | ||
| 2694 | for (i = 0, mn = module_names, m = modules; | 2693 | for (i = 0, mn = module_names, m = modules; |
| 2695 | i < nmod; ++i, ++m, mn += strlen(mn) + 1) { | 2694 | i < nmod; ++i, ++m, mn += strlen(mn) + 1) { |
| 2696 | struct new_module_info info; | 2695 | struct new_module_info info; |
| @@ -2770,13 +2769,14 @@ static int new_is_kernel_checksummed(void) | |||
| 2770 | } | 2769 | } |
| 2771 | 2770 | ||
| 2772 | 2771 | ||
| 2773 | static void new_create_this_module(struct obj_file *f, const char *m_name) | 2772 | static void new_create_this_module(struct obj_file *f, const char *m_name) |
| 2774 | { | 2773 | { |
| 2775 | struct obj_section *sec; | 2774 | struct obj_section *sec; |
| 2776 | 2775 | ||
| 2777 | sec = obj_create_alloced_section_first(f, ".this", tgt_sizeof_long, | 2776 | sec = obj_create_alloced_section_first(f, ".this", tgt_sizeof_long, |
| 2778 | sizeof(struct new_module)); | 2777 | sizeof(struct new_module)); |
| 2779 | memset(sec->contents, 0, sizeof(struct new_module)); | 2778 | /* done by obj_create_alloced_section_first: */ |
| 2779 | /*memset(sec->contents, 0, sizeof(struct new_module));*/ | ||
| 2780 | 2780 | ||
| 2781 | obj_add_symbol(f, SPFX "__this_module", -1, | 2781 | obj_add_symbol(f, SPFX "__this_module", -1, |
| 2782 | ELF_ST_INFO(STB_LOCAL, STT_OBJECT), sec->idx, 0, | 2782 | ELF_ST_INFO(STB_LOCAL, STT_OBJECT), sec->idx, 0, |
| @@ -3083,9 +3083,9 @@ static void obj_allocate_commons(struct obj_file *f) | |||
| 3083 | if (i == f->header.e_shnum) { | 3083 | if (i == f->header.e_shnum) { |
| 3084 | struct obj_section *sec; | 3084 | struct obj_section *sec; |
| 3085 | 3085 | ||
| 3086 | f->header.e_shnum++; | ||
| 3086 | f->sections = xrealloc_vector(f->sections, 2, i); | 3087 | f->sections = xrealloc_vector(f->sections, 2, i); |
| 3087 | f->sections[i] = sec = arch_new_section(); | 3088 | f->sections[i] = sec = arch_new_section(); |
| 3088 | f->header.e_shnum = i + 1; | ||
| 3089 | 3089 | ||
| 3090 | sec->header.sh_type = SHT_PROGBITS; | 3090 | sec->header.sh_type = SHT_PROGBITS; |
| 3091 | sec->header.sh_flags = SHF_WRITE | SHF_ALLOC; | 3091 | sec->header.sh_flags = SHF_WRITE | SHF_ALLOC; |
| @@ -3124,12 +3124,9 @@ static void obj_allocate_commons(struct obj_file *f) | |||
| 3124 | for (i = 0; i < f->header.e_shnum; ++i) { | 3124 | for (i = 0; i < f->header.e_shnum; ++i) { |
| 3125 | struct obj_section *s = f->sections[i]; | 3125 | struct obj_section *s = f->sections[i]; |
| 3126 | if (s->header.sh_type == SHT_NOBITS) { | 3126 | if (s->header.sh_type == SHT_NOBITS) { |
| 3127 | s->contents = NULL; | ||
| 3127 | if (s->header.sh_size != 0) | 3128 | if (s->header.sh_size != 0) |
| 3128 | s->contents = memset(xmalloc(s->header.sh_size), | 3129 | s->contents = xzalloc(s->header.sh_size), |
| 3129 | 0, s->header.sh_size); | ||
| 3130 | else | ||
| 3131 | s->contents = NULL; | ||
| 3132 | |||
| 3133 | s->header.sh_type = SHT_PROGBITS; | 3130 | s->header.sh_type = SHT_PROGBITS; |
| 3134 | } | 3131 | } |
| 3135 | } | 3132 | } |
| @@ -3354,8 +3351,7 @@ static struct obj_file *obj_load(FILE *fp, int loadprogbits UNUSED_PARAM) | |||
| 3354 | } | 3351 | } |
| 3355 | 3352 | ||
| 3356 | shnum = f->header.e_shnum; | 3353 | shnum = f->header.e_shnum; |
| 3357 | f->sections = xmalloc(sizeof(struct obj_section *) * shnum); | 3354 | f->sections = xzalloc(sizeof(struct obj_section *) * shnum); |
| 3358 | memset(f->sections, 0, sizeof(struct obj_section *) * shnum); | ||
| 3359 | 3355 | ||
| 3360 | section_headers = alloca(sizeof(ElfW(Shdr)) * shnum); | 3356 | section_headers = alloca(sizeof(ElfW(Shdr)) * shnum); |
| 3361 | fseek(fp, f->header.e_shoff, SEEK_SET); | 3357 | fseek(fp, f->header.e_shoff, SEEK_SET); |
| @@ -3391,14 +3387,13 @@ static struct obj_file *obj_load(FILE *fp, int loadprogbits UNUSED_PARAM) | |||
| 3391 | case SHT_SYMTAB: | 3387 | case SHT_SYMTAB: |
| 3392 | case SHT_STRTAB: | 3388 | case SHT_STRTAB: |
| 3393 | case SHT_RELM: | 3389 | case SHT_RELM: |
| 3390 | sec->contents = NULL; | ||
| 3394 | if (sec->header.sh_size > 0) { | 3391 | if (sec->header.sh_size > 0) { |
| 3395 | sec->contents = xmalloc(sec->header.sh_size); | 3392 | sec->contents = xzalloc(sec->header.sh_size); |
| 3396 | fseek(fp, sec->header.sh_offset, SEEK_SET); | 3393 | fseek(fp, sec->header.sh_offset, SEEK_SET); |
| 3397 | if (fread(sec->contents, sec->header.sh_size, 1, fp) != 1) { | 3394 | if (fread(sec->contents, sec->header.sh_size, 1, fp) != 1) { |
| 3398 | bb_perror_msg_and_die("error reading ELF section data"); | 3395 | bb_perror_msg_and_die("error reading ELF section data"); |
| 3399 | } | 3396 | } |
| 3400 | } else { | ||
| 3401 | sec->contents = NULL; | ||
| 3402 | } | 3397 | } |
| 3403 | break; | 3398 | break; |
| 3404 | 3399 | ||
