2
## 123_bfd_overflow_fix.dpatch
4
## DP: Description: Fix overflows in BFD ELF parsing code. (#308625)
5
## DP: Author: Alan Modra
6
## DP: Upstream status: Committed to trunk.
7
## DP: Date: 2005-05-09
8
## DP: URL: http://sources.redhat.com/ml/binutils/2005-05/msg00336.html
11
echo "`basename $0`: script expects -patch|-unpatch as argument" >&2
15
[ -f debian/patches/00patch-opts ] && . debian/patches/00patch-opts
16
patch_opts="${patch_opts:--f --no-backup-if-mismatch} ${2:+-d $2}"
19
-patch) patch -p1 ${patch_opts} < $0;;
20
-unpatch) patch -R -p1 ${patch_opts} < $0;;
22
echo "`basename $0`: script expects -patch|-unpatch as argument" >&2
29
diff -urNad binutils-2.15/bfd/elfcode.h /tmp/dpep.8QipP1/binutils-2.15/bfd/elfcode.h
30
--- binutils-2.15/bfd/elfcode.h 2004-05-17 20:36:02.000000000 +0100
31
+++ /tmp/dpep.8QipP1/binutils-2.15/bfd/elfcode.h 2005-05-21 20:18:52.355469043 +0100
34
if (i_ehdrp->e_shoff != 0)
36
+ bfd_signed_vma where = i_ehdrp->e_shoff;
38
+ if (where != (file_ptr) where)
39
+ goto got_wrong_format_error;
41
/* Seek to the section header table in the file. */
42
- if (bfd_seek (abfd, (file_ptr) i_ehdrp->e_shoff, SEEK_SET) != 0)
43
+ if (bfd_seek (abfd, (file_ptr) where, SEEK_SET) != 0)
46
/* Read the first section header at index 0, and convert to internal
48
/* If the section count is zero, the actual count is in the first
50
if (i_ehdrp->e_shnum == SHN_UNDEF)
51
- i_ehdrp->e_shnum = i_shdr.sh_size;
53
+ i_ehdrp->e_shnum = i_shdr.sh_size;
54
+ if (i_ehdrp->e_shnum != i_shdr.sh_size)
55
+ goto got_wrong_format_error;
58
/* And similarly for the string table index. */
59
if (i_ehdrp->e_shstrndx == SHN_XINDEX)
60
- i_ehdrp->e_shstrndx = i_shdr.sh_link;
62
+ i_ehdrp->e_shstrndx = i_shdr.sh_link;
63
+ if (i_ehdrp->e_shstrndx != i_shdr.sh_link)
64
+ goto got_wrong_format_error;
67
+ /* Sanity check that we can read all of the section headers.
68
+ It ought to be good enough to just read the last one. */
69
+ if (i_ehdrp->e_shnum != 1)
71
+ /* Check that we don't have a totally silly number of sections. */
72
+ if (i_ehdrp->e_shnum > (unsigned int) -1 / sizeof (x_shdr))
73
+ goto got_wrong_format_error;
75
+ where += (i_ehdrp->e_shnum - 1) * sizeof (x_shdr);
76
+ if (where != (file_ptr) where)
77
+ goto got_wrong_format_error;
78
+ if ((bfd_size_type) where <= i_ehdrp->e_shoff)
79
+ goto got_wrong_format_error;
81
+ if (bfd_seek (abfd, (file_ptr) where, SEEK_SET) != 0)
83
+ if (bfd_bread (&x_shdr, sizeof x_shdr, abfd) != sizeof (x_shdr))
86
+ /* Back to where we were. */
87
+ where = i_ehdrp->e_shoff + sizeof (x_shdr);
88
+ if (bfd_seek (abfd, (file_ptr) where, SEEK_SET) != 0)
93
+ /* A further sanity check. */
94
+ if (i_ehdrp->e_shstrndx >= i_ehdrp->e_shnum)
95
+ goto got_wrong_format_error;
97
/* Allocate space for a copy of the section header table in
99
if (i_ehdrp->e_shnum != 0)