~ubuntu-branches/ubuntu/hoary/binutils/hoary-security

« back to all changes in this revision

Viewing changes to debian/patches/500_security_bfd_overflow.dpatch

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2005-05-27 13:27:13 UTC
  • Revision ID: james.westby@ubuntu.com-20050527132713-texxzd820u1k053l
Tags: 2.15-5ubuntu2.2
Removed the additional checks from 500_security_bfd_overflow.dpatch since
it broke compilers. (Ubuntu #11249)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh -e
 
2
## 123_bfd_overflow_fix.dpatch
 
3
##
 
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
 
9
 
 
10
if [ $# -lt 1 ]; then
 
11
    echo "`basename $0`: script expects -patch|-unpatch as argument" >&2
 
12
    exit 1
 
13
fi
 
14
 
 
15
[ -f debian/patches/00patch-opts ] && . debian/patches/00patch-opts
 
16
patch_opts="${patch_opts:--f --no-backup-if-mismatch} ${2:+-d $2}"
 
17
 
 
18
case "$1" in
 
19
    -patch) patch -p1 ${patch_opts} < $0;;
 
20
    -unpatch) patch -R -p1 ${patch_opts} < $0;;
 
21
    *)
 
22
        echo "`basename $0`: script expects -patch|-unpatch as argument" >&2
 
23
        exit 1;;
 
24
esac
 
25
 
 
26
exit 0
 
27
 
 
28
@DPATCH@
 
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
 
32
@@ -611,8 +611,13 @@
 
33
 
 
34
   if (i_ehdrp->e_shoff != 0)
 
35
     {
 
36
+      bfd_signed_vma where = i_ehdrp->e_shoff;
 
37
+
 
38
+      if (where != (file_ptr) where)
 
39
+       goto got_wrong_format_error;
 
40
+
 
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)
 
44
        goto got_no_match;
 
45
 
 
46
       /* Read the first section header at index 0, and convert to internal
 
47
@@ -624,13 +629,50 @@
 
48
       /* If the section count is zero, the actual count is in the first
 
49
         section header.  */
 
50
       if (i_ehdrp->e_shnum == SHN_UNDEF)
 
51
-       i_ehdrp->e_shnum = i_shdr.sh_size;
 
52
+       {
 
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;
 
56
+       }
 
57
 
 
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;
 
61
+       {
 
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;
 
65
+       }
 
66
+
 
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)
 
70
+       {
 
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;
 
74
+
 
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;
 
80
+
 
81
+         if (bfd_seek (abfd, (file_ptr) where, SEEK_SET) != 0)
 
82
+           goto got_no_match;
 
83
+         if (bfd_bread (&x_shdr, sizeof x_shdr, abfd) != sizeof (x_shdr))
 
84
+           goto got_no_match;
 
85
+
 
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)
 
89
+           goto got_no_match;
 
90
+       }
 
91
     }
 
92
 
 
93
+  /* A further sanity check.  */
 
94
+  if (i_ehdrp->e_shstrndx >= i_ehdrp->e_shnum)
 
95
+    goto got_wrong_format_error;
 
96
+
 
97
   /* Allocate space for a copy of the section header table in
 
98
      internal form.  */
 
99
   if (i_ehdrp->e_shnum != 0)