1 --- elfutils/libelf/ChangeLog
2 +++ elfutils/libelf/ChangeLog
4 If section content hasn't been read yet, do it before looking for the
5 block size. If no section data present, infer size of section header.
7 +2005-05-17 Jakub Jelinek <jakub@redhat.com>
9 + * elf32_getphdr.c (elfw2(LIBELFBITS,getphdr)): Check if program header
10 + table fits into object's bounds.
11 + * elf_getshstrndx.c (elf_getshstrndx): Add elf->start_offset to
12 + elf->map_address. Check if first section header fits into object's
14 + * elf32_getshdr.c (elfw2(LIBELFBITS,getshdr)):
15 + Check if section header table fits into object's bounds.
16 + * elf_begin.c (get_shnum): Ensure section headers fits into
18 + (file_read_elf): Make sure scncnt is small enough to allocate both
19 + ElfXX_Shdr and Elf_Scn array. Make sure section and program header
20 + tables fit into object's bounds. Avoid memory leak on failure.
22 +2005-05-14 Jakub Jelinek <jakub@redhat.com>
24 + * libelfP.h (INVALID_NDX): Define.
25 + * gelf_getdyn.c (gelf_getdyn): Use it. Remove ndx < 0 test if any.
26 + * gelf_getlib.c (gelf_getlib): Likewise.
27 + * gelf_getmove.c (gelf_getmove): Likewise.
28 + * gelf_getrel.c (gelf_getrel): Likewise.
29 + * gelf_getrela.c (gelf_getrela): Likewise.
30 + * gelf_getsym.c (gelf_getsym): Likewise.
31 + * gelf_getsyminfo.c (gelf_getsyminfo): Likewise.
32 + * gelf_getsymshndx.c (gelf_getsymshndx): Likewise.
33 + * gelf_getversym.c (gelf_getversym): Likewise.
34 + * gelf_update_dyn.c (gelf_update_dyn): Likewise.
35 + * gelf_update_lib.c (gelf_update_lib): Likewise.
36 + * gelf_update_move.c (gelf_update_move): Likewise.
37 + * gelf_update_rel.c (gelf_update_rel): Likewise.
38 + * gelf_update_rela.c (gelf_update_rela): Likewise.
39 + * gelf_update_sym.c (gelf_update_sym): Likewise.
40 + * gelf_update_syminfo.c (gelf_update_syminfo): Likewise.
41 + * gelf_update_symshndx.c (gelf_update_symshndx): Likewise.
42 + * gelf_update_versym.c (gelf_update_versym): Likewise.
43 + * elf_newscn.c (elf_newscn): Check for overflow.
44 + * elf32_updatefile.c (__elfw2(LIBELFBITS,updatemmap)): Likewise.
45 + (__elfw2(LIBELFBITS,updatefile)): Likewise.
46 + * elf_begin.c (file_read_elf): Likewise.
47 + * elf32_newphdr.c (elfw2(LIBELFBITS,newphdr)): Likewise.
48 + * elf_getarsym.c (elf_getarsym): Likewise.
49 + * elf32_getshdr.c (elfw2(LIBELFBITS,getshdr)): Likewise.
50 2005-05-11 Ulrich Drepper <drepper@redhat.com>
52 * elf.h: Update again.
53 --- elfutils/libelf/elf32_getphdr.c
54 +++ elfutils/libelf/elf32_getphdr.c
55 @@ -107,6 +107,16 @@ __elfw2(LIBELFBITS,getphdr_wrlock) (elf)
57 if (elf->map_address != NULL)
59 + /* First see whether the information in the ELF header is
60 + valid and it does not ask for too much. */
61 + if (unlikely (ehdr->e_phoff >= elf->maximum_size)
62 + || unlikely (elf->maximum_size - ehdr->e_phoff < size))
64 + /* Something is wrong. */
65 + __libelf_seterrno (ELF_E_INVALID_PHDR);
69 /* All the data is already mapped. Use it. */
70 void *file_phdr = ((char *) elf->map_address
71 + elf->start_offset + ehdr->e_phoff);
72 --- elfutils/libelf/elf32_getshdr.c
73 +++ elfutils/libelf/elf32_getshdr.c
75 /* Return section header.
76 - Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005, 2007, 2009 Red Hat, Inc.
77 + Copyright (C) 1998-2009 Red Hat, Inc.
78 This file is part of Red Hat elfutils.
79 Written by Ulrich Drepper <drepper@redhat.com>, 1998.
81 @@ -81,7 +81,8 @@ load_shdr_wrlock (Elf_Scn *scn)
85 - if (__elf_getshdrnum_rdlock (elf, &shnum) != 0)
86 + if (__elf_getshdrnum_rdlock (elf, &shnum) != 0
87 + || shnum > SIZE_MAX / sizeof (ElfW2(LIBELFBITS,Shdr)))
89 size_t size = shnum * sizeof (ElfW2(LIBELFBITS,Shdr));
91 @@ -98,6 +99,16 @@ load_shdr_wrlock (Elf_Scn *scn)
93 if (elf->map_address != NULL)
95 + /* First see whether the information in the ELF header is
96 + valid and it does not ask for too much. */
97 + if (unlikely (ehdr->e_shoff >= elf->maximum_size)
98 + || unlikely (elf->maximum_size - ehdr->e_shoff < size))
100 + /* Something is wrong. */
101 + __libelf_seterrno (ELF_E_INVALID_SECTION_HEADER);
105 ElfW2(LIBELFBITS,Shdr) *notcvt;
107 /* All the data is already mapped. If we could use it
108 --- elfutils/libelf/elf32_newphdr.c
109 +++ elfutils/libelf/elf32_newphdr.c
110 @@ -135,6 +135,12 @@ elfw2(LIBELFBITS,newphdr) (elf, count)
112 || elf->state.ELFW(elf,LIBELFBITS).phdr == NULL)
114 + if (unlikely (count > SIZE_MAX / sizeof (ElfW2(LIBELFBITS,Phdr))))
120 /* Allocate a new program header with the appropriate number of
122 result = (ElfW2(LIBELFBITS,Phdr) *)
123 --- elfutils/libelf/elf32_updatefile.c
124 +++ elfutils/libelf/elf32_updatefile.c
125 @@ -223,6 +223,9 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf
126 /* Write all the sections. Well, only those which are modified. */
129 + if (unlikely (shnum > SIZE_MAX / sizeof (Elf_Scn *)))
132 Elf_ScnList *list = &elf->state.ELFW(elf,LIBELFBITS).scns;
133 Elf_Scn **scns = (Elf_Scn **) alloca (shnum * sizeof (Elf_Scn *));
134 char *const shdr_start = ((char *) elf->map_address + elf->start_offset
135 @@ -645,6 +648,10 @@ __elfw2(LIBELFBITS,updatefile) (Elf *elf
136 /* Write all the sections. Well, only those which are modified. */
139 + if (unlikely (shnum > SIZE_MAX / (sizeof (Elf_Scn *)
140 + + sizeof (ElfW2(LIBELFBITS,Shdr)))))
143 off_t shdr_offset = elf->start_offset + ehdr->e_shoff;
145 xfct_t shdr_fctp = __elf_xfctstom[__libelf_version - 1][EV_CURRENT - 1][ELFW(ELFCLASS, LIBELFBITS) - 1][ELF_T_SHDR];
146 --- elfutils/libelf/elf_begin.c
147 +++ elfutils/libelf/elf_begin.c
148 @@ -165,7 +165,8 @@ get_shnum (void *map_address, unsigned c
150 if (unlikely (result == 0) && ehdr.e32->e_shoff != 0)
152 - if (ehdr.e32->e_shoff + sizeof (Elf32_Shdr) > maxsize)
153 + if (unlikely (ehdr.e32->e_shoff >= maxsize)
154 + || unlikely (maxsize - ehdr.e32->e_shoff < sizeof (Elf32_Shdr)))
155 /* Cannot read the first section header. */
158 @@ -213,7 +214,8 @@ get_shnum (void *map_address, unsigned c
160 if (unlikely (result == 0) && ehdr.e64->e_shoff != 0)
162 - if (ehdr.e64->e_shoff + sizeof (Elf64_Shdr) > maxsize)
163 + if (unlikely (ehdr.e64->e_shoff >= maxsize)
164 + || unlikely (ehdr.e64->e_shoff + sizeof (Elf64_Shdr) > maxsize))
165 /* Cannot read the first section header. */
168 @@ -285,6 +287,15 @@ file_read_elf (int fildes, void *map_add
169 /* Could not determine the number of sections. */
172 + /* Check for too many sections. */
173 + if (e_ident[EI_CLASS] == ELFCLASS32)
175 + if (scncnt > SIZE_MAX / (sizeof (Elf_Scn) + sizeof (Elf32_Shdr)))
178 + else if (scncnt > SIZE_MAX / (sizeof (Elf_Scn) + sizeof (Elf64_Shdr)))
181 /* We can now allocate the memory. Even if there are no section headers,
182 we allocate space for a zeroth section in case we need it later. */
183 const size_t scnmax = (scncnt ?: (cmd == ELF_C_RDWR || cmd == ELF_C_RDWR_MMAP)
184 @@ -324,13 +335,33 @@ file_read_elf (int fildes, void *map_add
186 /* We can use the mmapped memory. */
187 elf->state.elf32.ehdr = ehdr;
189 + if (unlikely (ehdr->e_shoff >= maxsize)
190 + || unlikely (maxsize - ehdr->e_shoff
191 + < scncnt * sizeof (Elf32_Shdr)))
195 + __libelf_seterrno (ELF_E_INVALID_FILE);
198 elf->state.elf32.shdr
199 = (Elf32_Shdr *) ((char *) ehdr + ehdr->e_shoff);
200 - if (ehdr->e_phnum > 0)
201 - /* Assign a value only if there really is a program
202 - header. Otherwise the value remains NULL. */
203 - elf->state.elf32.phdr
204 - = (Elf32_Phdr *) ((char *) ehdr + ehdr->e_phoff);
206 + size_t phnum = ehdr->e_phnum;
207 + if (phnum == PN_XNUM && scncnt > 0)
208 + phnum = elf->state.elf32.shdr[0].sh_info;
211 + /* Assign a value only if there really is a program
212 + header. Otherwise the value remains NULL. */
213 + if (unlikely (ehdr->e_phoff >= maxsize)
214 + || unlikely (maxsize - ehdr->e_phoff
215 + < phnum * sizeof (Elf32_Phdr)))
217 + elf->state.elf32.phdr
218 + = (Elf32_Phdr *) ((char *) ehdr + ehdr->e_phoff);
221 for (size_t cnt = 0; cnt < scncnt; ++cnt)
223 @@ -412,13 +443,28 @@ file_read_elf (int fildes, void *map_add
225 /* We can use the mmapped memory. */
226 elf->state.elf64.ehdr = ehdr;
228 + if (unlikely (ehdr->e_shoff >= maxsize)
229 + || unlikely (ehdr->e_shoff
230 + + scncnt * sizeof (Elf32_Shdr) > maxsize))
232 elf->state.elf64.shdr
233 = (Elf64_Shdr *) ((char *) ehdr + ehdr->e_shoff);
234 - if (ehdr->e_phnum > 0)
235 - /* Assign a value only if there really is a program
236 - header. Otherwise the value remains NULL. */
237 - elf->state.elf64.phdr
238 - = (Elf64_Phdr *) ((char *) ehdr + ehdr->e_phoff);
240 + size_t phnum = ehdr->e_phnum;
241 + if (phnum == PN_XNUM && scncnt > 0)
242 + phnum = elf->state.elf64.shdr[0].sh_info;
245 + /* Assign a value only if there really is a program
246 + header. Otherwise the value remains NULL. */
247 + if (unlikely (ehdr->e_phoff >= maxsize)
248 + || unlikely (ehdr->e_phoff
249 + + phnum * sizeof (Elf32_Phdr) > maxsize))
251 + elf->state.elf64.phdr
252 + = (Elf64_Phdr *) ((char *) ehdr + ehdr->e_phoff);
255 for (size_t cnt = 0; cnt < scncnt; ++cnt)
257 --- elfutils/libelf/elf_getarsym.c
258 +++ elfutils/libelf/elf_getarsym.c
259 @@ -179,6 +179,9 @@ elf_getarsym (elf, ptr)
260 size_t index_size = atol (tmpbuf);
262 if (SARMAG + sizeof (struct ar_hdr) + index_size > elf->maximum_size
263 +#if SIZE_MAX <= 4294967295U
264 + || n >= SIZE_MAX / sizeof (Elf_Arsym)
266 || n * sizeof (uint32_t) > index_size)
268 /* This index table cannot be right since it does not fit into
269 --- elfutils/libelf/elf_getshdrstrndx.c
270 +++ elfutils/libelf/elf_getshdrstrndx.c
271 @@ -125,10 +125,25 @@ elf_getshdrstrndx (elf, dst)
272 if (elf->map_address != NULL
273 && elf->state.elf32.ehdr->e_ident[EI_DATA] == MY_ELFDATA
275 - || (((size_t) ((char *) elf->map_address + offset))
276 + || (((size_t) ((char *) elf->map_address
277 + + elf->start_offset + offset))
278 & (__alignof__ (Elf32_Shdr) - 1)) == 0))
279 - /* We can directly access the memory. */
280 - num = ((Elf32_Shdr *) (elf->map_address + offset))->sh_link;
282 + /* First see whether the information in the ELF header is
283 + valid and it does not ask for too much. */
284 + if (unlikely (elf->maximum_size - offset
285 + < sizeof (Elf32_Shdr)))
287 + /* Something is wrong. */
288 + __libelf_seterrno (ELF_E_INVALID_SECTION_HEADER);
293 + /* We can directly access the memory. */
294 + num = ((Elf32_Shdr *) (elf->map_address + elf->start_offset
295 + + offset))->sh_link;
299 /* We avoid reading in all the section headers. Just read
300 @@ -163,10 +178,25 @@ elf_getshdrstrndx (elf, dst)
301 if (elf->map_address != NULL
302 && elf->state.elf64.ehdr->e_ident[EI_DATA] == MY_ELFDATA
304 - || (((size_t) ((char *) elf->map_address + offset))
305 + || (((size_t) ((char *) elf->map_address
306 + + elf->start_offset + offset))
307 & (__alignof__ (Elf64_Shdr) - 1)) == 0))
308 - /* We can directly access the memory. */
309 - num = ((Elf64_Shdr *) (elf->map_address + offset))->sh_link;
311 + /* First see whether the information in the ELF header is
312 + valid and it does not ask for too much. */
313 + if (unlikely (elf->maximum_size - offset
314 + < sizeof (Elf64_Shdr)))
316 + /* Something is wrong. */
317 + __libelf_seterrno (ELF_E_INVALID_SECTION_HEADER);
322 + /* We can directly access the memory. */
323 + num = ((Elf64_Shdr *) (elf->map_address + elf->start_offset
324 + + offset))->sh_link;
328 /* We avoid reading in all the section headers. Just read
329 --- elfutils/libelf/elf_newscn.c
330 +++ elfutils/libelf/elf_newscn.c
331 @@ -104,10 +104,18 @@ elf_newscn (elf)
334 /* We must allocate a new element. */
336 + Elf_ScnList *newp = NULL;
338 assert (elf->state.elf.scnincr > 0);
341 +#if SIZE_MAX <= 4294967295U
342 + likely (elf->state.elf.scnincr
343 + < SIZE_MAX / 2 / sizeof (Elf_Scn) - sizeof (Elf_ScnList))
348 newp = (Elf_ScnList *) calloc (sizeof (Elf_ScnList)
349 + ((elf->state.elf.scnincr *= 2)
350 * sizeof (Elf_Scn)), 1);
351 --- elfutils/libelf/gelf_getdyn.c
352 +++ elfutils/libelf/gelf_getdyn.c
354 /* Get information from dynamic table at the given index.
355 - Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
356 + Copyright (C) 2000-2009 Red Hat, Inc.
357 This file is part of Red Hat elfutils.
358 Written by Ulrich Drepper <drepper@redhat.com>, 2000.
360 @@ -93,7 +93,7 @@ gelf_getdyn (data, ndx, dst)
361 table entries has to be adopted. The user better has provided
362 a buffer where we can store the information. While copying the
363 data we are converting the format. */
364 - if (unlikely ((ndx + 1) * sizeof (Elf32_Dyn) > data_scn->d.d_size))
365 + if (INVALID_NDX (ndx, Elf32_Dyn, &data_scn->d))
367 __libelf_seterrno (ELF_E_INVALID_INDEX);
369 @@ -114,7 +114,7 @@ gelf_getdyn (data, ndx, dst)
371 /* The data is already in the correct form. Just make sure the
373 - if (unlikely ((ndx + 1) * sizeof (GElf_Dyn) > data_scn->d.d_size))
374 + if (INVALID_NDX (ndx, GElf_Dyn, &data_scn->d))
376 __libelf_seterrno (ELF_E_INVALID_INDEX);
378 --- elfutils/libelf/gelf_getlib.c
379 +++ elfutils/libelf/gelf_getlib.c
381 /* Get library from table at the given index.
382 - Copyright (C) 2004 Red Hat, Inc.
383 + Copyright (C) 2004-2009 Red Hat, Inc.
384 This file is part of Red Hat elfutils.
385 Written by Ulrich Drepper <drepper@redhat.com>, 2004.
387 @@ -86,7 +86,7 @@ gelf_getlib (data, ndx, dst)
388 /* The data is already in the correct form. Just make sure the
390 GElf_Lib *result = NULL;
391 - if (unlikely ((ndx + 1) * sizeof (GElf_Lib) > data->d_size))
392 + if (INVALID_NDX (ndx, GElf_Lib, data))
393 __libelf_seterrno (ELF_E_INVALID_INDEX);
396 --- elfutils/libelf/gelf_getmove.c
397 +++ elfutils/libelf/gelf_getmove.c
399 /* Get move structure at the given index.
400 - Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
401 + Copyright (C) 2000-2009 Red Hat, Inc.
402 This file is part of Red Hat elfutils.
403 Written by Ulrich Drepper <drepper@redhat.com>, 2000.
405 @@ -83,7 +83,7 @@ gelf_getmove (data, ndx, dst)
407 /* The data is already in the correct form. Just make sure the
409 - if (unlikely ((ndx + 1) * sizeof (GElf_Move) > data->d_size))
410 + if (INVALID_NDX (ndx, GElf_Move, data))
412 __libelf_seterrno (ELF_E_INVALID_INDEX);
414 --- elfutils/libelf/gelf_getrela.c
415 +++ elfutils/libelf/gelf_getrela.c
417 /* Get RELA relocation information at given index.
418 - Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
419 + Copyright (C) 2000-2009 Red Hat, Inc.
420 This file is part of Red Hat elfutils.
421 Written by Ulrich Drepper <drepper@redhat.com>, 2000.
423 @@ -71,12 +71,6 @@ gelf_getrela (data, ndx, dst)
424 if (data_scn == NULL)
427 - if (unlikely (ndx < 0))
429 - __libelf_seterrno (ELF_E_INVALID_INDEX);
433 if (unlikely (data_scn->d.d_type != ELF_T_RELA))
435 __libelf_seterrno (ELF_E_INVALID_HANDLE);
436 @@ -93,7 +87,7 @@ gelf_getrela (data, ndx, dst)
437 if (scn->elf->class == ELFCLASS32)
439 /* We have to convert the data. */
440 - if (unlikely ((ndx + 1) * sizeof (Elf32_Rela) > data_scn->d.d_size))
441 + if (INVALID_NDX (ndx, Elf32_Rela, &data_scn->d))
443 __libelf_seterrno (ELF_E_INVALID_INDEX);
445 @@ -114,7 +108,7 @@ gelf_getrela (data, ndx, dst)
447 /* Simply copy the data after we made sure we are actually getting
449 - if (unlikely ((ndx + 1) * sizeof (Elf64_Rela) > data_scn->d.d_size))
450 + if (INVALID_NDX (ndx, Elf64_Rela, &data_scn->d))
452 __libelf_seterrno (ELF_E_INVALID_INDEX);
454 --- elfutils/libelf/gelf_getrel.c
455 +++ elfutils/libelf/gelf_getrel.c
457 /* Get REL relocation information at given index.
458 - Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
459 + Copyright (C) 2000-2009 Red Hat, Inc.
460 This file is part of Red Hat elfutils.
461 Written by Ulrich Drepper <drepper@redhat.com>, 2000.
463 @@ -71,12 +71,6 @@ gelf_getrel (data, ndx, dst)
464 if (data_scn == NULL)
467 - if (unlikely (ndx < 0))
469 - __libelf_seterrno (ELF_E_INVALID_INDEX);
473 if (unlikely (data_scn->d.d_type != ELF_T_REL))
475 __libelf_seterrno (ELF_E_INVALID_HANDLE);
476 @@ -93,7 +87,7 @@ gelf_getrel (data, ndx, dst)
477 if (scn->elf->class == ELFCLASS32)
479 /* We have to convert the data. */
480 - if (unlikely ((ndx + 1) * sizeof (Elf32_Rel) > data_scn->d.d_size))
481 + if (INVALID_NDX (ndx, Elf32_Rel, &data_scn->d))
483 __libelf_seterrno (ELF_E_INVALID_INDEX);
485 @@ -113,7 +107,7 @@ gelf_getrel (data, ndx, dst)
487 /* Simply copy the data after we made sure we are actually getting
489 - if (unlikely ((ndx + 1) * sizeof (Elf64_Rel) > data_scn->d.d_size))
490 + if (INVALID_NDX (ndx, Elf64_Rel, &data_scn->d))
492 __libelf_seterrno (ELF_E_INVALID_INDEX);
494 --- elfutils/libelf/gelf_getsym.c
495 +++ elfutils/libelf/gelf_getsym.c
497 /* Get symbol information from symbol table at the given index.
498 - Copyright (C) 1999, 2000, 2001, 2002 Red Hat, Inc.
499 + Copyright (C) 1999-2009 Red Hat, Inc.
500 This file is part of Red Hat elfutils.
501 Written by Ulrich Drepper <drepper@redhat.com>, 1999.
503 @@ -90,7 +90,7 @@ gelf_getsym (data, ndx, dst)
504 table entries has to be adopted. The user better has provided
505 a buffer where we can store the information. While copying the
506 data we are converting the format. */
507 - if (unlikely ((ndx + 1) * sizeof (Elf32_Sym) > data->d_size))
508 + if (INVALID_NDX (ndx, Elf32_Sym, data))
510 __libelf_seterrno (ELF_E_INVALID_INDEX);
512 @@ -119,7 +119,7 @@ gelf_getsym (data, ndx, dst)
514 /* The data is already in the correct form. Just make sure the
516 - if (unlikely ((ndx + 1) * sizeof (GElf_Sym) > data->d_size))
517 + if (INVALID_NDX (ndx, GElf_Sym, data))
519 __libelf_seterrno (ELF_E_INVALID_INDEX);
521 --- elfutils/libelf/gelf_getsyminfo.c
522 +++ elfutils/libelf/gelf_getsyminfo.c
524 /* Get additional symbol information from symbol table at the given index.
525 - Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
526 + Copyright (C) 2000-2009 Red Hat, Inc.
527 This file is part of Red Hat elfutils.
528 Written by Ulrich Drepper <drepper@redhat.com>, 2000.
530 @@ -84,7 +84,7 @@ gelf_getsyminfo (data, ndx, dst)
532 /* The data is already in the correct form. Just make sure the
534 - if (unlikely ((ndx + 1) * sizeof (GElf_Syminfo) > data->d_size))
535 + if (INVALID_NDX (ndx, GElf_Syminfo, data))
537 __libelf_seterrno (ELF_E_INVALID_INDEX);
539 --- elfutils/libelf/gelf_getsymshndx.c
540 +++ elfutils/libelf/gelf_getsymshndx.c
542 /* Get symbol information and separate section index from symbol table
544 - Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
545 + Copyright (C) 2000-2009 Red Hat, Inc.
546 This file is part of Red Hat elfutils.
547 Written by Ulrich Drepper <drepper@redhat.com>, 2000.
549 @@ -90,7 +90,7 @@ gelf_getsymshndx (symdata, shndxdata, nd
550 section index table. */
551 if (likely (shndxdata_scn != NULL))
553 - if (unlikely ((ndx + 1) * sizeof (Elf32_Word) > shndxdata_scn->d.d_size))
554 + if (INVALID_NDX (ndx, Elf32_Word, &shndxdata_scn->d))
556 __libelf_seterrno (ELF_E_INVALID_INDEX);
558 @@ -110,7 +110,7 @@ gelf_getsymshndx (symdata, shndxdata, nd
559 table entries has to be adopted. The user better has provided
560 a buffer where we can store the information. While copying the
561 data we are converting the format. */
562 - if (unlikely ((ndx + 1) * sizeof (Elf32_Sym) > symdata->d_size))
563 + if (INVALID_NDX (ndx, Elf32_Sym, symdata))
565 __libelf_seterrno (ELF_E_INVALID_INDEX);
567 @@ -139,7 +139,7 @@ gelf_getsymshndx (symdata, shndxdata, nd
569 /* The data is already in the correct form. Just make sure the
571 - if (unlikely ((ndx + 1) * sizeof (GElf_Sym) > symdata->d_size))
572 + if (INVALID_NDX (ndx, GElf_Sym, symdata))
574 __libelf_seterrno (ELF_E_INVALID_INDEX);
576 --- elfutils/libelf/gelf_getversym.c
577 +++ elfutils/libelf/gelf_getversym.c
579 /* Get symbol version information at the given index.
580 - Copyright (C) 1999, 2000, 2001, 2002 Red Hat, Inc.
581 + Copyright (C) 1999-2009 Red Hat, Inc.
582 This file is part of Red Hat elfutils.
583 Written by Ulrich Drepper <drepper@redhat.com>, 1999.
585 @@ -92,7 +92,7 @@ gelf_getversym (data, ndx, dst)
587 /* The data is already in the correct form. Just make sure the
589 - if (unlikely ((ndx + 1) * sizeof (GElf_Versym) > data->d_size))
590 + if (INVALID_NDX (ndx, GElf_Versym, data))
592 __libelf_seterrno (ELF_E_INVALID_INDEX);
594 --- elfutils/libelf/gelf_update_dyn.c
595 +++ elfutils/libelf/gelf_update_dyn.c
597 /* Update information in dynamic table at the given index.
598 - Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
599 + Copyright (C) 2000-2009 Red Hat, Inc.
600 This file is part of Red Hat elfutils.
601 Written by Ulrich Drepper <drepper@redhat.com>, 2000.
603 @@ -71,12 +71,6 @@ gelf_update_dyn (data, ndx, src)
607 - if (unlikely (ndx < 0))
609 - __libelf_seterrno (ELF_E_INVALID_INDEX);
613 if (unlikely (data_scn->d.d_type != ELF_T_DYN))
615 /* The type of the data better should match. */
616 @@ -102,7 +96,7 @@ gelf_update_dyn (data, ndx, src)
619 /* Check whether we have to resize the data buffer. */
620 - if (unlikely ((ndx + 1) * sizeof (Elf32_Dyn) > data_scn->d.d_size))
621 + if (INVALID_NDX (ndx, Elf32_Dyn, &data_scn->d))
623 __libelf_seterrno (ELF_E_INVALID_INDEX);
625 @@ -116,7 +110,7 @@ gelf_update_dyn (data, ndx, src)
628 /* Check whether we have to resize the data buffer. */
629 - if (unlikely ((ndx + 1) * sizeof (Elf64_Dyn) > data_scn->d.d_size))
630 + if (INVALID_NDX (ndx, Elf64_Dyn, &data_scn->d))
632 __libelf_seterrno (ELF_E_INVALID_INDEX);
634 --- elfutils/libelf/gelf_update_lib.c
635 +++ elfutils/libelf/gelf_update_lib.c
637 /* Update library in table at the given index.
638 - Copyright (C) 2004 Red Hat, Inc.
639 + Copyright (C) 2004-2009 Red Hat, Inc.
640 This file is part of Red Hat elfutils.
641 Written by Ulrich Drepper <drepper@redhat.com>, 2004.
643 @@ -68,12 +68,6 @@ gelf_update_lib (data, ndx, src)
647 - if (unlikely (ndx < 0))
649 - __libelf_seterrno (ELF_E_INVALID_INDEX);
653 Elf_Data_Scn *data_scn = (Elf_Data_Scn *) data;
654 if (unlikely (data_scn->d.d_type != ELF_T_LIB))
656 @@ -87,7 +81,7 @@ gelf_update_lib (data, ndx, src)
658 /* Check whether we have to resize the data buffer. */
660 - if (unlikely ((ndx + 1) * sizeof (Elf64_Lib) > data_scn->d.d_size))
661 + if (INVALID_NDX (ndx, Elf64_Lib, &data_scn->d))
662 __libelf_seterrno (ELF_E_INVALID_INDEX);
665 --- elfutils/libelf/gelf_update_move.c
666 +++ elfutils/libelf/gelf_update_move.c
668 /* Update move structure at the given index.
669 - Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
670 + Copyright (C) 2000-2009 Red Hat, Inc.
671 This file is part of Red Hat elfutils.
672 Written by Ulrich Drepper <drepper@redhat.com>, 2000.
674 @@ -75,8 +75,7 @@ gelf_update_move (data, ndx, src)
675 assert (sizeof (GElf_Move) == sizeof (Elf64_Move));
677 /* Check whether we have to resize the data buffer. */
678 - if (unlikely (ndx < 0)
679 - || unlikely ((ndx + 1) * sizeof (GElf_Move) > data_scn->d.d_size))
680 + if (INVALID_NDX (ndx, GElf_Move, &data_scn->d))
682 __libelf_seterrno (ELF_E_INVALID_INDEX);
684 --- elfutils/libelf/gelf_update_rela.c
685 +++ elfutils/libelf/gelf_update_rela.c
687 /* Update RELA relocation information at given index.
688 - Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
689 + Copyright (C) 2000-2009 Red Hat, Inc.
690 This file is part of Red Hat elfutils.
691 Written by Ulrich Drepper <drepper@redhat.com>, 2000.
693 @@ -68,12 +68,6 @@ gelf_update_rela (Elf_Data *dst, int ndx
697 - if (unlikely (ndx < 0))
699 - __libelf_seterrno (ELF_E_INVALID_INDEX);
703 if (unlikely (data_scn->d.d_type != ELF_T_RELA))
705 /* The type of the data better should match. */
706 @@ -101,7 +95,7 @@ gelf_update_rela (Elf_Data *dst, int ndx
709 /* Check whether we have to resize the data buffer. */
710 - if (unlikely ((ndx + 1) * sizeof (Elf32_Rela) > data_scn->d.d_size))
711 + if (INVALID_NDX (ndx, Elf32_Rela, &data_scn->d))
713 __libelf_seterrno (ELF_E_INVALID_INDEX);
715 @@ -117,7 +111,7 @@ gelf_update_rela (Elf_Data *dst, int ndx
718 /* Check whether we have to resize the data buffer. */
719 - if (unlikely ((ndx + 1) * sizeof (Elf64_Rela) > data_scn->d.d_size))
720 + if (INVALID_NDX (ndx, Elf64_Rela, &data_scn->d))
722 __libelf_seterrno (ELF_E_INVALID_INDEX);
724 --- elfutils/libelf/gelf_update_rel.c
725 +++ elfutils/libelf/gelf_update_rel.c
727 /* Update REL relocation information at given index.
728 - Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
729 + Copyright (C) 2000-2009 Red Hat, Inc.
730 This file is part of Red Hat elfutils.
731 Written by Ulrich Drepper <drepper@redhat.com>, 2000.
733 @@ -68,12 +68,6 @@ gelf_update_rel (Elf_Data *dst, int ndx,
737 - if (unlikely (ndx < 0))
739 - __libelf_seterrno (ELF_E_INVALID_INDEX);
743 if (unlikely (data_scn->d.d_type != ELF_T_REL))
745 /* The type of the data better should match. */
746 @@ -99,7 +93,7 @@ gelf_update_rel (Elf_Data *dst, int ndx,
749 /* Check whether we have to resize the data buffer. */
750 - if (unlikely ((ndx + 1) * sizeof (Elf32_Rel) > data_scn->d.d_size))
751 + if (INVALID_NDX (ndx, Elf32_Rel, &data_scn->d))
753 __libelf_seterrno (ELF_E_INVALID_INDEX);
755 @@ -114,7 +108,7 @@ gelf_update_rel (Elf_Data *dst, int ndx,
758 /* Check whether we have to resize the data buffer. */
759 - if (unlikely ((ndx + 1) * sizeof (Elf64_Rel) > data_scn->d.d_size))
760 + if (INVALID_NDX (ndx, Elf64_Rel, &data_scn->d))
762 __libelf_seterrno (ELF_E_INVALID_INDEX);
764 --- elfutils/libelf/gelf_update_sym.c
765 +++ elfutils/libelf/gelf_update_sym.c
767 /* Update symbol information in symbol table at the given index.
768 - Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
769 + Copyright (C) 2000-2009 Red Hat, Inc.
770 This file is part of Red Hat elfutils.
771 Written by Ulrich Drepper <drepper@redhat.com>, 2000.
773 @@ -72,12 +72,6 @@ gelf_update_sym (data, ndx, src)
777 - if (unlikely (ndx < 0))
779 - __libelf_seterrno (ELF_E_INVALID_INDEX);
783 if (unlikely (data_scn->d.d_type != ELF_T_SYM))
785 /* The type of the data better should match. */
786 @@ -102,7 +96,7 @@ gelf_update_sym (data, ndx, src)
789 /* Check whether we have to resize the data buffer. */
790 - if (unlikely ((ndx + 1) * sizeof (Elf32_Sym) > data_scn->d.d_size))
791 + if (INVALID_NDX (ndx, Elf32_Sym, &data_scn->d))
793 __libelf_seterrno (ELF_E_INVALID_INDEX);
795 @@ -125,7 +119,7 @@ gelf_update_sym (data, ndx, src)
798 /* Check whether we have to resize the data buffer. */
799 - if (unlikely ((ndx + 1) * sizeof (Elf64_Sym) > data_scn->d.d_size))
800 + if (INVALID_NDX (ndx, Elf64_Sym, &data_scn->d))
802 __libelf_seterrno (ELF_E_INVALID_INDEX);
804 --- elfutils/libelf/gelf_update_syminfo.c
805 +++ elfutils/libelf/gelf_update_syminfo.c
807 /* Update additional symbol information in symbol table at the given index.
808 - Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
809 + Copyright (C) 2000-2009 Red Hat, Inc.
810 This file is part of Red Hat elfutils.
811 Written by Ulrich Drepper <drepper@redhat.com>, 2000.
813 @@ -72,12 +72,6 @@ gelf_update_syminfo (data, ndx, src)
817 - if (unlikely (ndx < 0))
819 - __libelf_seterrno (ELF_E_INVALID_INDEX);
823 if (unlikely (data_scn->d.d_type != ELF_T_SYMINFO))
825 /* The type of the data better should match. */
826 @@ -93,7 +87,7 @@ gelf_update_syminfo (data, ndx, src)
827 rwlock_wrlock (scn->elf->lock);
829 /* Check whether we have to resize the data buffer. */
830 - if (unlikely ((ndx + 1) * sizeof (GElf_Syminfo) > data_scn->d.d_size))
831 + if (INVALID_NDX (ndx, GElf_Syminfo, &data_scn->d))
833 __libelf_seterrno (ELF_E_INVALID_INDEX);
835 --- elfutils/libelf/gelf_update_symshndx.c
836 +++ elfutils/libelf/gelf_update_symshndx.c
838 /* Update symbol information and section index in symbol table at the
840 - Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
841 + Copyright (C) 2000-2009 Red Hat, Inc.
842 This file is part of Red Hat elfutils.
843 Written by Ulrich Drepper <drepper@redhat.com>, 2000.
845 @@ -77,12 +77,6 @@ gelf_update_symshndx (symdata, shndxdata
849 - if (unlikely (ndx < 0))
851 - __libelf_seterrno (ELF_E_INVALID_INDEX);
855 if (unlikely (symdata_scn->d.d_type != ELF_T_SYM))
857 /* The type of the data better should match. */
858 @@ -128,7 +122,7 @@ gelf_update_symshndx (symdata, shndxdata
861 /* Check whether we have to resize the data buffer. */
862 - if (unlikely ((ndx + 1) * sizeof (Elf32_Sym) > symdata_scn->d.d_size))
863 + if (INVALID_NDX (ndx, Elf32_Sym, &symdata_scn->d))
865 __libelf_seterrno (ELF_E_INVALID_INDEX);
867 @@ -151,7 +145,7 @@ gelf_update_symshndx (symdata, shndxdata
870 /* Check whether we have to resize the data buffer. */
871 - if (unlikely ((ndx + 1) * sizeof (Elf64_Sym) > symdata_scn->d.d_size))
872 + if (INVALID_NDX (ndx, Elf64_Sym, &symdata_scn->d))
874 __libelf_seterrno (ELF_E_INVALID_INDEX);
876 --- elfutils/libelf/gelf_update_versym.c
877 +++ elfutils/libelf/gelf_update_versym.c
879 /* Update symbol version information.
880 - Copyright (C) 2001, 2002 Red Hat, Inc.
881 + Copyright (C) 2001-2009 Red Hat, Inc.
882 This file is part of Red Hat elfutils.
883 Written by Ulrich Drepper <drepper@redhat.com>, 2001.
885 @@ -75,8 +75,7 @@ gelf_update_versym (data, ndx, src)
886 assert (sizeof (GElf_Versym) == sizeof (Elf64_Versym));
888 /* Check whether we have to resize the data buffer. */
889 - if (unlikely (ndx < 0)
890 - || unlikely ((ndx + 1) * sizeof (GElf_Versym) > data_scn->d.d_size))
891 + if (INVALID_NDX (ndx, GElf_Versym, &data_scn->d))
893 __libelf_seterrno (ELF_E_INVALID_INDEX);
895 --- elfutils/libelf/libelfP.h
896 +++ elfutils/libelf/libelfP.h
897 @@ -608,4 +608,8 @@ extern uint32_t __libelf_crc32 (uint32_t
898 /* Align offset to 4 bytes as needed for note name and descriptor data. */
899 #define NOTE_ALIGN(n) (((n) + 3) & -4U)
901 +/* Convenience macro. */
902 +#define INVALID_NDX(ndx, type, data) \
903 + unlikely ((data)->d_size / sizeof (type) <= (unsigned int) (ndx))
905 #endif /* libelfP.h */
906 --- elfutils/src/ChangeLog
907 +++ elfutils/src/ChangeLog
908 @@ -1532,6 +1532,16 @@
909 object symbols or symbols with unknown type.
910 (check_rel): Likewise.
912 +2005-06-09 Roland McGrath <roland@redhat.com>
914 + * readelf.c (handle_dynamic, handle_symtab): Check for bogus sh_link.
915 + (handle_verneed, handle_verdef, handle_versym, handle_hash): Likewise.
916 + (handle_scngrp): Check for bogus sh_info.
918 + * strip.c (handle_elf): Check for bogus values in sh_link, sh_info,
919 + st_shndx, e_shstrndx, and SHT_GROUP or SHT_SYMTAB_SHNDX data.
920 + Don't use assert on input values, instead bail with "illformed" error.
922 2005-06-08 Roland McGrath <roland@redhat.com>
924 * readelf.c (print_ops): Add consts.
925 @@ -1577,6 +1587,19 @@
927 * readelf.c (dwarf_tag_string): Add new tags.
929 +2005-05-17 Jakub Jelinek <jakub@redhat.com>
931 + * elflint.c (check_hash): Don't check entries beyond end of section.
932 + (check_note): Don't crash if gelf_rawchunk fails.
933 + (section_name): Return <invalid> if gelf_getshdr returns NULL.
935 +2005-05-14 Jakub Jelinek <jakub@redhat.com>
937 + * elflint.c (section_name): Return "<invalid>" instead of
938 + crashing on invalid section name.
939 + (check_symtab, is_rel_dyn, check_rela, check_rel, check_dynamic,
940 + check_symtab_shndx, check_hash, check_versym): Robustify.
942 2005-05-08 Roland McGrath <roland@redhat.com>
944 * strip.c (handle_elf): Don't translate hash and versym data formats,
945 --- elfutils/src/elflint.c
946 +++ elfutils/src/elflint.c
947 @@ -131,6 +131,10 @@ static uint32_t shstrndx;
948 /* Array to count references in section groups. */
951 +/* Numbers of sections and program headers. */
952 +static unsigned int shnum;
953 +static unsigned int phnum;
957 main (int argc, char *argv[])
958 @@ -319,10 +323,19 @@ section_name (Ebl *ebl, int idx)
964 + if ((unsigned int) idx > shnum)
965 + return "<invalid>";
967 shdr = gelf_getshdr (elf_getscn (ebl->elf, idx), &shdr_mem);
969 + return "<invalid>";
971 - return elf_strptr (ebl->elf, shstrndx, shdr->sh_name);
972 + ret = elf_strptr (ebl->elf, shstrndx, shdr->sh_name);
974 + return "<invalid>";
979 @@ -344,11 +357,6 @@ static const int valid_e_machine[] =
980 (sizeof (valid_e_machine) / sizeof (valid_e_machine[0]))
983 -/* Numbers of sections and program headers. */
984 -static unsigned int shnum;
985 -static unsigned int phnum;
989 check_elf_header (Ebl *ebl, GElf_Ehdr *ehdr, size_t size)
991 @@ -632,7 +640,8 @@ section [%2d] '%s': symbol table cannot
995 - if (shdr->sh_entsize != gelf_fsize (ebl->elf, ELF_T_SYM, 1, EV_CURRENT))
996 + size_t sh_entsize = gelf_fsize (ebl->elf, ELF_T_SYM, 1, EV_CURRENT);
997 + if (shdr->sh_entsize != sh_entsize)
999 section [%2u] '%s': entry size is does not match ElfXX_Sym\n"),
1000 idx, section_name (ebl, idx));
1001 @@ -670,7 +679,7 @@ section [%2d] '%s': XINDEX for zeroth en
1002 xndxscnidx, section_name (ebl, xndxscnidx));
1005 - for (size_t cnt = 1; cnt < shdr->sh_size / shdr->sh_entsize; ++cnt)
1006 + for (size_t cnt = 1; cnt < shdr->sh_size / sh_entsize; ++cnt)
1008 sym = gelf_getsymshndx (data, xndxdata, cnt, &sym_mem, &xndx);
1010 @@ -690,7 +699,8 @@ section [%2d] '%s': symbol %zu: invalid
1013 name = elf_strptr (ebl->elf, shdr->sh_link, sym->st_name);
1014 - assert (name != NULL);
1015 + assert (name != NULL
1016 + || strshdr->sh_type != SHT_STRTAB);
1019 if (sym->st_shndx == SHN_XINDEX)
1020 @@ -1038,9 +1048,11 @@ is_rel_dyn (Ebl *ebl, const GElf_Ehdr *e
1022 GElf_Shdr rcshdr_mem;
1023 const GElf_Shdr *rcshdr = gelf_getshdr (scn, &rcshdr_mem);
1024 - assert (rcshdr != NULL);
1026 - if (rcshdr->sh_type == SHT_DYNAMIC)
1027 + if (rcshdr == NULL)
1030 + if (rcshdr->sh_type == SHT_DYNAMIC && rcshdr->sh_entsize)
1032 /* Found the dynamic section. Look through it. */
1033 Elf_Data *d = elf_getdata (scn, NULL);
1034 @@ -1050,7 +1062,9 @@ is_rel_dyn (Ebl *ebl, const GElf_Ehdr *e
1037 GElf_Dyn *dyn = gelf_getdyn (d, cnt, &dyn_mem);
1038 - assert (dyn != NULL);
1043 if (dyn->d_tag == DT_RELCOUNT)
1045 @@ -1064,7 +1078,9 @@ section [%2d] '%s': DT_RELCOUNT used for
1046 /* Does the number specified number of relative
1047 relocations exceed the total number of
1049 - if (dyn->d_un.d_val > shdr->sh_size / shdr->sh_entsize)
1050 + if (shdr->sh_entsize != 0
1051 + && dyn->d_un.d_val > (shdr->sh_size
1052 + / shdr->sh_entsize))
1054 section [%2d] '%s': DT_RELCOUNT value %d too high for this section\n"),
1055 idx, section_name (ebl, idx),
1056 @@ -1224,7 +1240,8 @@ section [%2d] '%s': no relocations for m
1060 - if (shdr->sh_entsize != gelf_fsize (ebl->elf, reltype, 1, EV_CURRENT))
1061 + size_t sh_entsize = gelf_fsize (ebl->elf, reltype, 1, EV_CURRENT);
1062 + if (shdr->sh_entsize != sh_entsize)
1063 ERROR (gettext (reltype == ELF_T_RELA ? "\
1064 section [%2d] '%s': section entry size does not match ElfXX_Rela\n" : "\
1065 section [%2d] '%s': section entry size does not match ElfXX_Rel\n"),
1066 @@ -1447,7 +1464,8 @@ check_rela (Ebl *ebl, GElf_Ehdr *ehdr, G
1067 Elf_Data *symdata = elf_getdata (symscn, NULL);
1068 enum load_state state = state_undecided;
1070 - for (size_t cnt = 0; cnt < shdr->sh_size / shdr->sh_entsize; ++cnt)
1071 + size_t sh_entsize = gelf_fsize (ebl->elf, ELF_T_RELA, 1, EV_CURRENT);
1072 + for (size_t cnt = 0; cnt < shdr->sh_size / sh_entsize; ++cnt)
1075 GElf_Rela *rela = gelf_getrela (data, cnt, &rela_mem);
1076 @@ -1497,7 +1515,8 @@ check_rel (Ebl *ebl, GElf_Ehdr *ehdr, GE
1077 Elf_Data *symdata = elf_getdata (symscn, NULL);
1078 enum load_state state = state_undecided;
1080 - for (size_t cnt = 0; cnt < shdr->sh_size / shdr->sh_entsize; ++cnt)
1081 + size_t sh_entsize = gelf_fsize (ebl->elf, ELF_T_REL, 1, EV_CURRENT);
1082 + for (size_t cnt = 0; cnt < shdr->sh_size / sh_entsize; ++cnt)
1085 GElf_Rel *rel = gelf_getrel (data, cnt, &rel_mem);
1086 @@ -1600,7 +1619,8 @@ section [%2d] '%s': referenced as string
1087 shdr->sh_link, section_name (ebl, shdr->sh_link),
1088 idx, section_name (ebl, idx));
1090 - if (shdr->sh_entsize != gelf_fsize (ebl->elf, ELF_T_DYN, 1, EV_CURRENT))
1091 + size_t sh_entsize = gelf_fsize (ebl->elf, ELF_T_DYN, 1, EV_CURRENT);
1092 + if (shdr->sh_entsize != sh_entsize)
1094 section [%2d] '%s': section entry size does not match ElfXX_Dyn\n"),
1095 idx, section_name (ebl, idx));
1096 @@ -1610,7 +1630,7 @@ section [%2d] '%s': section entry size d
1097 idx, section_name (ebl, idx));
1099 bool non_null_warned = false;
1100 - for (cnt = 0; cnt < shdr->sh_size / shdr->sh_entsize; ++cnt)
1101 + for (cnt = 0; cnt < shdr->sh_size / sh_entsize; ++cnt)
1104 GElf_Dyn *dyn = gelf_getdyn (data, cnt, &dyn_mem);
1105 @@ -1891,6 +1911,8 @@ section [%2d] '%s': entry size does not
1106 idx, section_name (ebl, idx));
1109 + && shdr->sh_entsize
1110 + && symshdr->sh_entsize
1111 && (shdr->sh_size / shdr->sh_entsize
1112 < symshdr->sh_size / symshdr->sh_entsize))
1114 @@ -1917,6 +1939,12 @@ section [%2d] '%s': extended section ind
1117 Elf_Data *data = elf_getdata (elf_getscn (ebl->elf, idx), NULL);
1120 + ERROR (gettext ("section [%2d] '%s': cannot get section data\n"),
1121 + idx, section_name (ebl, idx));
1125 if (*((Elf32_Word *) data->d_buf) != 0)
1126 ERROR (gettext ("symbol 0 should have zero extended section index\n"));
1127 @@ -1959,7 +1987,7 @@ section [%2d] '%s': hash table section i
1129 size_t maxidx = nchain;
1131 - if (symshdr != NULL)
1132 + if (symshdr != NULL && symshdr->sh_entsize != 0)
1134 size_t symsize = symshdr->sh_size / symshdr->sh_entsize;
1136 @@ -1970,18 +1998,28 @@ section [%2d] '%s': hash table section i
1140 + Elf32_Word *buf = (Elf32_Word *) data->d_buf;
1141 + Elf32_Word *end = (Elf32_Word *) ((char *) data->d_buf + shdr->sh_size);
1143 for (cnt = 2; cnt < 2 + nbucket; ++cnt)
1144 - if (((Elf32_Word *) data->d_buf)[cnt] >= maxidx)
1146 + if (buf + cnt >= end)
1148 + else if (buf[cnt] >= maxidx)
1150 section [%2d] '%s': hash bucket reference %zu out of bounds\n"),
1151 idx, section_name (ebl, idx), cnt - 2);
1154 for (; cnt < 2 + nbucket + nchain; ++cnt)
1155 - if (((Elf32_Word *) data->d_buf)[cnt] >= maxidx)
1157 + if (buf + cnt >= end)
1159 + else if (buf[cnt] >= maxidx)
1161 section [%2d] '%s': hash chain reference %zu out of bounds\n"),
1162 idx, section_name (ebl, idx), cnt - 2 - nbucket);
1167 @@ -2011,18 +2049,28 @@ section [%2d] '%s': hash table section i
1171 + Elf64_Xword *buf = (Elf64_Xword *) data->d_buf;
1172 + Elf64_Xword *end = (Elf64_Xword *) ((char *) data->d_buf + shdr->sh_size);
1174 for (cnt = 2; cnt < 2 + nbucket; ++cnt)
1175 - if (((Elf64_Xword *) data->d_buf)[cnt] >= maxidx)
1177 + if (buf + cnt >= end)
1179 + else if (buf[cnt] >= maxidx)
1181 section [%2d] '%s': hash bucket reference %zu out of bounds\n"),
1182 idx, section_name (ebl, idx), cnt - 2);
1185 for (; cnt < 2 + nbucket + nchain; ++cnt)
1186 - if (((Elf64_Xword *) data->d_buf)[cnt] >= maxidx)
1188 + if (buf + cnt >= end)
1190 + else if (buf[cnt] >= maxidx)
1192 section [%2d] '%s': hash chain reference %" PRIu64 " out of bounds\n"),
1193 - idx, section_name (ebl, idx), (uint64_t) (cnt - 2 - nbucket));
1194 + idx, section_name (ebl, idx), (uint64_t) cnt - 2 - nbucket);
1199 @@ -2047,7 +2095,7 @@ section [%2d] '%s': bitmask size not pow
1200 if (shdr->sh_size < (4 + bitmask_words + nbuckets) * sizeof (Elf32_Word))
1203 -section [%2d] '%s': hash table section is too small (is %ld, expected at least%ld)\n"),
1204 +section [%2d] '%s': hash table section is too small (is %ld, expected at least %ld)\n"),
1205 idx, section_name (ebl, idx), (long int) shdr->sh_size,
1206 (long int) ((4 + bitmask_words + nbuckets) * sizeof (Elf32_Word)));
1208 @@ -2719,8 +2767,9 @@ section [%2d] '%s' refers in sh_link to
1210 /* The number of elements in the version symbol table must be the
1211 same as the number of symbols. */
1212 - if (shdr->sh_size / shdr->sh_entsize
1213 - != symshdr->sh_size / symshdr->sh_entsize)
1214 + if (shdr->sh_entsize && symshdr->sh_entsize
1215 + && (shdr->sh_size / shdr->sh_entsize
1216 + != symshdr->sh_size / symshdr->sh_entsize))
1218 section [%2d] '%s' has different number of entries than symbol table [%2d] '%s'\n"),
1219 idx, section_name (ebl, idx),
1220 --- elfutils/src/readelf.c
1221 +++ elfutils/src/readelf.c
1222 @@ -1170,6 +1170,8 @@ handle_scngrp (Ebl *ebl, Elf_Scn *scn, G
1223 Elf32_Word *grpref = (Elf32_Word *) data->d_buf;
1226 + GElf_Sym *sym = gelf_getsym (symdata, shdr->sh_info, &sym_mem);
1228 printf ((grpref[0] & GRP_COMDAT)
1230 \nCOMDAT section group [%2zu] '%s' with signature '%s' contains %zu entry:\n",
1231 @@ -1182,8 +1184,8 @@ handle_scngrp (Ebl *ebl, Elf_Scn *scn, G
1232 data->d_size / sizeof (Elf32_Word) - 1),
1234 elf_strptr (ebl->elf, shstrndx, shdr->sh_name),
1235 - elf_strptr (ebl->elf, symshdr->sh_link,
1236 - gelf_getsym (symdata, shdr->sh_info, &sym_mem)->st_name)
1237 + (sym == NULL ? NULL
1238 + : elf_strptr (ebl->elf, symshdr->sh_link, sym->st_name))
1239 ?: gettext ("<INVALID SYMBOL>"),
1240 data->d_size / sizeof (Elf32_Word) - 1);
1242 @@ -1334,7 +1336,8 @@ static void
1243 handle_dynamic (Ebl *ebl, Elf_Scn *scn, GElf_Shdr *shdr)
1245 int class = gelf_getclass (ebl->elf);
1247 + GElf_Shdr glink_mem;
1252 @@ -1349,6 +1352,11 @@ handle_dynamic (Ebl *ebl, Elf_Scn *scn,
1253 error (EXIT_FAILURE, 0,
1254 gettext ("cannot get section header string table index"));
1256 + glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), &glink_mem);
1257 + if (glink == NULL)
1258 + error (EXIT_FAILURE, 0, gettext ("invalid sh_link value in section %Zu"),
1259 + elf_ndxscn (scn));
1261 printf (ngettext ("\
1262 \nDynamic segment contains %lu entry:\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 " Link to section: [%2u] '%s'\n",
1264 @@ -1358,9 +1366,7 @@ handle_dynamic (Ebl *ebl, Elf_Scn *scn,
1265 class == ELFCLASS32 ? 10 : 18, shdr->sh_addr,
1267 (int) shdr->sh_link,
1268 - elf_strptr (ebl->elf, shstrndx,
1269 - gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link),
1270 - &glink)->sh_name));
1271 + elf_strptr (ebl->elf, shstrndx, glink->sh_name));
1272 fputs_unlocked (gettext (" Type Value\n"), stdout);
1274 for (cnt = 0; cnt < shdr->sh_size / shdr->sh_entsize; ++cnt)
1275 @@ -1943,6 +1949,13 @@ handle_symtab (Ebl *ebl, Elf_Scn *scn, G
1276 error (EXIT_FAILURE, 0,
1277 gettext ("cannot get section header string table index"));
1279 + GElf_Shdr glink_mem;
1280 + GElf_Shdr *glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link),
1282 + if (glink == NULL)
1283 + error (EXIT_FAILURE, 0, gettext ("invalid sh_link value in section %Zu"),
1284 + elf_ndxscn (scn));
1286 /* Now we can compute the number of entries in the section. */
1287 unsigned int nsyms = data->d_size / (class == ELFCLASS32
1288 ? sizeof (Elf32_Sym)
1289 @@ -1953,15 +1966,12 @@ handle_symtab (Ebl *ebl, Elf_Scn *scn, G
1291 (unsigned int) elf_ndxscn (scn),
1292 elf_strptr (ebl->elf, shstrndx, shdr->sh_name), nsyms);
1294 printf (ngettext (" %lu local symbol String table: [%2u] '%s'\n",
1295 " %lu local symbols String table: [%2u] '%s'\n",
1297 (unsigned long int) shdr->sh_info,
1298 (unsigned int) shdr->sh_link,
1299 - elf_strptr (ebl->elf, shstrndx,
1300 - gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link),
1301 - &glink)->sh_name));
1302 + elf_strptr (ebl->elf, shstrndx, glink->sh_name));
1304 fputs_unlocked (class == ELFCLASS32
1306 @@ -2197,7 +2207,13 @@ handle_verneed (Ebl *ebl, Elf_Scn *scn,
1307 error (EXIT_FAILURE, 0,
1308 gettext ("cannot get section header string table index"));
1311 + GElf_Shdr glink_mem;
1312 + GElf_Shdr *glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link),
1314 + if (glink == NULL)
1315 + error (EXIT_FAILURE, 0, gettext ("invalid sh_link value in section %Zu"),
1316 + elf_ndxscn (scn));
1318 printf (ngettext ("\
1319 \nVersion needs section [%2u] '%s' contains %d entry:\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 " Link to section: [%2u] '%s'\n",
1321 @@ -2208,9 +2224,7 @@ handle_verneed (Ebl *ebl, Elf_Scn *scn,
1322 class == ELFCLASS32 ? 10 : 18, shdr->sh_addr,
1324 (unsigned int) shdr->sh_link,
1325 - elf_strptr (ebl->elf, shstrndx,
1326 - gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link),
1327 - &glink)->sh_name));
1328 + elf_strptr (ebl->elf, shstrndx, glink->sh_name));
1330 unsigned int offset = 0;
1331 for (int cnt = shdr->sh_info; --cnt >= 0; )
1332 @@ -2263,8 +2277,14 @@ handle_verdef (Ebl *ebl, Elf_Scn *scn, G
1333 error (EXIT_FAILURE, 0,
1334 gettext ("cannot get section header string table index"));
1336 + GElf_Shdr glink_mem;
1337 + GElf_Shdr *glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link),
1339 + if (glink == NULL)
1340 + error (EXIT_FAILURE, 0, gettext ("invalid sh_link value in section %Zu"),
1341 + elf_ndxscn (scn));
1343 int class = gelf_getclass (ebl->elf);
1345 printf (ngettext ("\
1346 \nVersion definition section [%2u] '%s' contains %d entry:\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 " Link to section: [%2u] '%s'\n",
1348 @@ -2276,9 +2296,7 @@ handle_verdef (Ebl *ebl, Elf_Scn *scn, G
1349 class == ELFCLASS32 ? 10 : 18, shdr->sh_addr,
1351 (unsigned int) shdr->sh_link,
1352 - elf_strptr (ebl->elf, shstrndx,
1353 - gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link),
1354 - &glink)->sh_name));
1355 + elf_strptr (ebl->elf, shstrndx, glink->sh_name));
1357 unsigned int offset = 0;
1358 for (int cnt = shdr->sh_info; --cnt >= 0; )
1359 @@ -2540,8 +2558,14 @@ handle_versym (Ebl *ebl, Elf_Scn *scn, G
1363 + GElf_Shdr glink_mem;
1364 + GElf_Shdr *glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link),
1366 + if (glink == NULL)
1367 + error (EXIT_FAILURE, 0, gettext ("invalid sh_link value in section %Zu"),
1368 + elf_ndxscn (scn));
1370 /* Print the header. */
1372 printf (ngettext ("\
1373 \nVersion symbols section [%2u] '%s' contains %d entry:\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 " Link to section: [%2u] '%s'",
1375 @@ -2553,9 +2577,7 @@ handle_versym (Ebl *ebl, Elf_Scn *scn, G
1376 class == ELFCLASS32 ? 10 : 18, shdr->sh_addr,
1378 (unsigned int) shdr->sh_link,
1379 - elf_strptr (ebl->elf, shstrndx,
1380 - gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link),
1381 - &glink)->sh_name));
1382 + elf_strptr (ebl->elf, shstrndx, glink->sh_name));
1384 /* Now we can finally look at the actual contents of this section. */
1385 for (unsigned int cnt = 0; cnt < shdr->sh_size / shdr->sh_entsize; ++cnt)
1386 @@ -2607,7 +2629,17 @@ print_hash_info (Ebl *ebl, Elf_Scn *scn,
1387 for (Elf32_Word cnt = 0; cnt < nbucket; ++cnt)
1388 ++counts[lengths[cnt]];
1391 + GElf_Shdr glink_mem;
1392 + GElf_Shdr *glink = gelf_getshdr (elf_getscn (ebl->elf,
1395 + if (glink == NULL)
1397 + error (0, 0, gettext ("invalid sh_link value in section %Zu"),
1398 + elf_ndxscn (scn));
1402 printf (ngettext ("\
1403 \nHistogram for bucket list length in section [%2u] '%s' (total of %d bucket):\n Addr: %#0*" PRIx64 " Offset: %#08" PRIx64 " Link to section: [%2u] '%s'\n",
1405 @@ -2620,9 +2652,7 @@ print_hash_info (Ebl *ebl, Elf_Scn *scn,
1408 (unsigned int) shdr->sh_link,
1409 - elf_strptr (ebl->elf, shstrndx,
1410 - gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link),
1411 - &glink)->sh_name));
1412 + elf_strptr (ebl->elf, shstrndx, glink->sh_name));
1414 if (extrastr != NULL)
1415 fputs (extrastr, stdout);
1416 @@ -4263,6 +4293,16 @@ print_debug_aranges_section (Dwfl_Module
1420 + GElf_Shdr glink_mem;
1422 + glink = gelf_getshdr (elf_getscn (ebl->elf, shdr->sh_link), &glink_mem);
1423 + if (glink == NULL)
1425 + error (0, 0, gettext ("invalid sh_link value in section %Zu"),
1426 + elf_ndxscn (scn));
1430 printf (ngettext ("\
1431 \nDWARF section [%2zu] '%s' at offset %#" PRIx64 " contains %zu entry:\n",
1433 --- elfutils/src/strip.c
1434 +++ elfutils/src/strip.c
1435 @@ -545,6 +545,11 @@ handle_elf (int fd, Elf *elf, const char
1439 + if (shstrndx >= shnum)
1442 +#define elf_assert(test) do { if (!(test)) goto illformed; } while (0)
1444 /* Storage for section information. We leave room for two more
1445 entries since we unconditionally create a section header string
1446 table. Maybe some weird tool created an ELF file without one.
1447 @@ -566,7 +571,7 @@ handle_elf (int fd, Elf *elf, const char
1449 /* This should always be true (i.e., there should not be any
1450 holes in the numbering). */
1451 - assert (elf_ndxscn (scn) == cnt);
1452 + elf_assert (elf_ndxscn (scn) == cnt);
1454 shdr_info[cnt].scn = scn;
1456 @@ -579,6 +584,7 @@ handle_elf (int fd, Elf *elf, const char
1457 shdr_info[cnt].shdr.sh_name);
1458 if (shdr_info[cnt].name == NULL)
1461 error (0, 0, gettext ("illformed file '%s'"), fname);
1464 @@ -588,6 +594,8 @@ handle_elf (int fd, Elf *elf, const char
1466 /* Remember the shdr.sh_link value. */
1467 shdr_info[cnt].old_sh_link = shdr_info[cnt].shdr.sh_link;
1468 + if (shdr_info[cnt].old_sh_link >= shnum)
1471 /* Sections in files other than relocatable object files which
1472 are not loaded can be freely moved by us. In relocatable
1473 @@ -600,7 +608,7 @@ handle_elf (int fd, Elf *elf, const char
1474 appropriate reference. */
1475 if (unlikely (shdr_info[cnt].shdr.sh_type == SHT_SYMTAB_SHNDX))
1477 - assert (shdr_info[shdr_info[cnt].shdr.sh_link].symtab_idx == 0);
1478 + elf_assert (shdr_info[shdr_info[cnt].shdr.sh_link].symtab_idx == 0);
1479 shdr_info[shdr_info[cnt].shdr.sh_link].symtab_idx = cnt;
1481 else if (unlikely (shdr_info[cnt].shdr.sh_type == SHT_GROUP))
1482 @@ -617,7 +625,12 @@ handle_elf (int fd, Elf *elf, const char
1484 inner < shdr_info[cnt].data->d_size / sizeof (Elf32_Word);
1487 + if (grpref[inner] < shnum)
1488 shdr_info[grpref[inner]].group_idx = cnt;
1493 if (inner == 1 || (inner == 2 && (grpref[0] & GRP_COMDAT) == 0))
1494 /* If the section group contains only one element and this
1495 @@ -628,7 +641,7 @@ handle_elf (int fd, Elf *elf, const char
1497 else if (unlikely (shdr_info[cnt].shdr.sh_type == SHT_GNU_versym))
1499 - assert (shdr_info[shdr_info[cnt].shdr.sh_link].version_idx == 0);
1500 + elf_assert (shdr_info[shdr_info[cnt].shdr.sh_link].version_idx == 0);
1501 shdr_info[shdr_info[cnt].shdr.sh_link].version_idx = cnt;
1504 @@ -636,7 +649,7 @@ handle_elf (int fd, Elf *elf, const char
1505 discarded right away. */
1506 if ((shdr_info[cnt].shdr.sh_flags & SHF_GROUP) != 0)
1508 - assert (shdr_info[cnt].group_idx != 0);
1509 + elf_assert (shdr_info[cnt].group_idx != 0);
1511 if (shdr_info[shdr_info[cnt].group_idx].idx == 0)
1513 @@ -711,11 +724,15 @@ handle_elf (int fd, Elf *elf, const char
1515 /* If a relocation section is marked as being removed make
1516 sure the section it is relocating is removed, too. */
1517 - if ((shdr_info[cnt].shdr.sh_type == SHT_REL
1518 + if (shdr_info[cnt].shdr.sh_type == SHT_REL
1519 || shdr_info[cnt].shdr.sh_type == SHT_RELA)
1520 - && shdr_info[shdr_info[cnt].shdr.sh_info].idx != 0)
1522 + if (shdr_info[cnt].shdr.sh_info >= shnum)
1524 + else if (shdr_info[shdr_info[cnt].shdr.sh_info].idx != 0)
1525 shdr_info[cnt].idx = 1;
1529 if (shdr_info[cnt].idx == 1)
1531 @@ -742,7 +759,7 @@ handle_elf (int fd, Elf *elf, const char
1532 if (shdr_info[cnt].symtab_idx != 0
1533 && shdr_info[shdr_info[cnt].symtab_idx].data == NULL)
1535 - assert (shdr_info[cnt].shdr.sh_type == SHT_SYMTAB);
1536 + elf_assert (shdr_info[cnt].shdr.sh_type == SHT_SYMTAB);
1538 shdr_info[shdr_info[cnt].symtab_idx].data
1539 = elf_getdata (shdr_info[shdr_info[cnt].symtab_idx].scn,
1540 @@ -782,6 +799,9 @@ handle_elf (int fd, Elf *elf, const char
1541 else if (scnidx == SHN_XINDEX)
1544 + if (scnidx >= shnum)
1547 if (shdr_info[scnidx].idx == 0)
1548 /* This symbol table has a real symbol in
1549 a discarded section. So preserve the
1550 @@ -812,12 +832,16 @@ handle_elf (int fd, Elf *elf, const char
1553 /* Handle references through sh_info. */
1554 - if (SH_INFO_LINK_P (&shdr_info[cnt].shdr)
1555 - && shdr_info[shdr_info[cnt].shdr.sh_info].idx == 0)
1556 + if (SH_INFO_LINK_P (&shdr_info[cnt].shdr))
1558 + if (shdr_info[cnt].shdr.sh_info >= shnum)
1560 + else if ( shdr_info[shdr_info[cnt].shdr.sh_info].idx == 0)
1562 shdr_info[shdr_info[cnt].shdr.sh_info].idx = 1;
1563 changes |= shdr_info[cnt].shdr.sh_info < cnt;
1567 /* Mark the section as investigated. */
1568 shdr_info[cnt].idx = 2;
1569 @@ -956,7 +980,7 @@ handle_elf (int fd, Elf *elf, const char
1570 error (EXIT_FAILURE, 0, gettext ("while generating output file: %s"),
1573 - assert (elf_ndxscn (shdr_info[cnt].newscn) == shdr_info[cnt].idx);
1574 + elf_assert (elf_ndxscn (shdr_info[cnt].newscn) == shdr_info[cnt].idx);
1576 /* Add this name to the section header string table. */
1577 shdr_info[cnt].se = ebl_strtabadd (shst, shdr_info[cnt].name, 0);
1578 @@ -993,7 +1017,7 @@ handle_elf (int fd, Elf *elf, const char
1579 error (EXIT_FAILURE, 0,
1580 gettext ("while create section header section: %s"),
1582 - assert (elf_ndxscn (shdr_info[cnt].newscn) == shdr_info[cnt].idx);
1583 + elf_assert (elf_ndxscn (shdr_info[cnt].newscn) == shdr_info[cnt].idx);
1585 shdr_info[cnt].data = elf_newdata (shdr_info[cnt].newscn);
1586 if (shdr_info[cnt].data == NULL)
1587 @@ -1049,7 +1073,7 @@ handle_elf (int fd, Elf *elf, const char
1588 error (EXIT_FAILURE, 0,
1589 gettext ("while create section header section: %s"),
1591 - assert (elf_ndxscn (shdr_info[cnt].newscn) == idx);
1592 + elf_assert (elf_ndxscn (shdr_info[cnt].newscn) == idx);
1594 /* Finalize the string table and fill in the correct indices in the
1596 @@ -1139,20 +1163,20 @@ handle_elf (int fd, Elf *elf, const char
1597 shndxdata = elf_getdata (shdr_info[shdr_info[cnt].symtab_idx].scn,
1600 - assert ((versiondata->d_size / sizeof (Elf32_Word))
1601 + elf_assert ((versiondata->d_size / sizeof (Elf32_Word))
1602 >= shdr_info[cnt].data->d_size / elsize);
1605 if (shdr_info[cnt].version_idx != 0)
1607 - assert (shdr_info[cnt].shdr.sh_type == SHT_DYNSYM);
1608 + elf_assert (shdr_info[cnt].shdr.sh_type == SHT_DYNSYM);
1609 /* This section has associated version
1610 information. We have to modify that
1611 information, too. */
1612 versiondata = elf_getdata (shdr_info[shdr_info[cnt].version_idx].scn,
1615 - assert ((versiondata->d_size / sizeof (GElf_Versym))
1616 + elf_assert ((versiondata->d_size / sizeof (GElf_Versym))
1617 >= shdr_info[cnt].data->d_size / elsize);
1620 @@ -1207,7 +1231,7 @@ handle_elf (int fd, Elf *elf, const char
1621 sec = shdr_info[sym->st_shndx].idx;
1624 - assert (shndxdata != NULL);
1625 + elf_assert (shndxdata != NULL);
1627 sec = shdr_info[xshndx].idx;
1629 @@ -1228,7 +1252,7 @@ handle_elf (int fd, Elf *elf, const char
1633 - assert (sec < SHN_LORESERVE || shndxdata != NULL);
1634 + elf_assert (sec < SHN_LORESERVE || shndxdata != NULL);
1636 if ((inner != destidx || nshndx != sym->st_shndx
1637 || (shndxdata != NULL && nxshndx != xshndx))
1638 @@ -1252,7 +1276,7 @@ handle_elf (int fd, Elf *elf, const char
1639 || shdr_info[cnt].debug_data == NULL)
1640 /* This is a section symbol for a section which has
1642 - assert (GELF_ST_TYPE (sym->st_info) == STT_SECTION);
1643 + elf_assert (GELF_ST_TYPE (sym->st_info) == STT_SECTION);
1646 if (destidx != inner)
1647 @@ -1439,11 +1463,11 @@ handle_elf (int fd, Elf *elf, const char
1650 GElf_Sym *sym = gelf_getsym (symd, inner, &sym_mem);
1651 - assert (sym != NULL);
1652 + elf_assert (sym != NULL);
1654 const char *name = elf_strptr (elf, strshndx,
1656 - assert (name != NULL);
1657 + elf_assert (name != NULL);
1658 size_t hidx = elf_hash (name) % nbucket;
1660 if (bucket[hidx] == 0)
1661 @@ -1462,7 +1486,7 @@ handle_elf (int fd, Elf *elf, const char
1664 /* Alpha and S390 64-bit use 64-bit SHT_HASH entries. */
1665 - assert (shdr_info[cnt].shdr.sh_entsize
1666 + elf_assert (shdr_info[cnt].shdr.sh_entsize
1667 == sizeof (Elf64_Xword));
1669 Elf64_Xword *bucket = (Elf64_Xword *) hashd->d_buf;
1670 @@ -1493,11 +1517,11 @@ handle_elf (int fd, Elf *elf, const char
1673 GElf_Sym *sym = gelf_getsym (symd, inner, &sym_mem);
1674 - assert (sym != NULL);
1675 + elf_assert (sym != NULL);
1677 const char *name = elf_strptr (elf, strshndx,
1679 - assert (name != NULL);
1680 + elf_assert (name != NULL);
1681 size_t hidx = elf_hash (name) % nbucket;
1683 if (bucket[hidx] == 0)