add missing file for previous patch
[external/binutils.git] / packaging / fixbug13534_2.patch
1 commit 433cc73f9df08a1435b4d07a7bd3eed20f0c3dcd
2 Author: Francois Gouget <fgouget@codeweavers.com>
3 Date:   Tue Dec 20 19:39:41 2011 +0100
4
5     bfd: Refuse to create an invalid archive when an archive element is too big.
6     
7     The archive format stores element sizes as a 10 character string and thus cannot handle anything 10GB or more.
8
9 diff --git a/bfd/archive.c b/bfd/archive.c
10 index 5c5b3d4..05aba6c 100644
11 --- a/bfd/archive.c
12 +++ b/bfd/archive.c
13 @@ -179,13 +179,18 @@ _bfd_ar_spacepad (char *p, size_t n, const char *fmt, long val)
14      memcpy (p, buf, n);
15  }
16  \f
17 -void
18 +int
19  _bfd_ar_sizepad (char *p, size_t n, bfd_size_type size)
20  {
21    static char buf[21];
22    size_t len;
23    snprintf (buf, sizeof (buf), "%-10" BFD_VMA_FMT "u", size);
24    len = strlen (buf);
25 +  if (len > n)
26 +    {
27 +      bfd_set_error(bfd_error_file_too_big);
28 +      return 0;
29 +    }
30    if (len < n)
31      {
32        memcpy (p, buf, len);
33 @@ -193,6 +198,7 @@ _bfd_ar_sizepad (char *p, size_t n, bfd_size_type size)
34      }
35    else
36      memcpy (p, buf, n);
37 +  return 1;
38  }
39  \f
40  bfd_boolean
41 @@ -1786,8 +1792,9 @@ _bfd_bsd44_write_ar_hdr (bfd *archive, bfd *abfd)
42  
43        BFD_ASSERT (padded_len == arch_eltdata (abfd)->extra_size);
44  
45 -      _bfd_ar_sizepad (hdr->ar_size, sizeof (hdr->ar_size),
46 -                        arch_eltdata (abfd)->parsed_size + padded_len);
47 +      if (!_bfd_ar_sizepad (hdr->ar_size, sizeof (hdr->ar_size),
48 +                            arch_eltdata (abfd)->parsed_size + padded_len))
49 +        return FALSE;
50  
51        if (bfd_bwrite (hdr, sizeof (*hdr), archive) != sizeof (*hdr))
52          return FALSE;
53 @@ -1907,8 +1914,8 @@ bfd_ar_hdr_from_filesystem (bfd *abfd, const char *filename, bfd *member)
54                        status.st_gid);
55    _bfd_ar_spacepad (hdr->ar_mode, sizeof (hdr->ar_mode), "%-8lo",
56                      status.st_mode);
57 -  _bfd_ar_sizepad (hdr->ar_size, sizeof (hdr->ar_size),
58 -                    status.st_size);
59 +  if (!_bfd_ar_sizepad (hdr->ar_size, sizeof (hdr->ar_size), status.st_size))
60 +    return NULL;
61    memcpy (hdr->ar_fmag, ARFMAG, 2);
62    ared->parsed_size = status.st_size;
63    ared->arch_header = (char *) hdr;
64 @@ -2148,8 +2155,9 @@ _bfd_write_archive_contents (bfd *arch)
65        memset (&hdr, ' ', sizeof (struct ar_hdr));
66        memcpy (hdr.ar_name, ename, strlen (ename));
67        /* Round size up to even number in archive header.  */
68 -      _bfd_ar_sizepad (hdr.ar_size, sizeof (hdr.ar_size),
69 -                        (elength + 1) & ~(bfd_size_type) 1);
70 +      if (!_bfd_ar_sizepad (hdr.ar_size, sizeof (hdr.ar_size),
71 +                            (elength + 1) & ~(bfd_size_type) 1))
72 +        return FALSE;
73        memcpy (hdr.ar_fmag, ARFMAG, 2);
74        if ((bfd_bwrite (&hdr, sizeof (struct ar_hdr), arch)
75            != sizeof (struct ar_hdr))
76 @@ -2425,7 +2433,8 @@ bsd_write_armap (bfd *arch,
77                      bfd_ardata (arch)->armap_timestamp);
78    _bfd_ar_spacepad (hdr.ar_uid, sizeof (hdr.ar_uid), "%ld", uid);
79    _bfd_ar_spacepad (hdr.ar_gid, sizeof (hdr.ar_gid), "%ld", gid);
80 -  _bfd_ar_sizepad (hdr.ar_size, sizeof (hdr.ar_size), mapsize);
81 +  if (!_bfd_ar_sizepad (hdr.ar_size, sizeof (hdr.ar_size), mapsize))
82 +    return FALSE;
83    memcpy (hdr.ar_fmag, ARFMAG, 2);
84    if (bfd_bwrite (&hdr, sizeof (struct ar_hdr), arch)
85        != sizeof (struct ar_hdr))
86 @@ -2580,7 +2589,8 @@ coff_write_armap (bfd *arch,
87  
88    memset (&hdr, ' ', sizeof (struct ar_hdr));
89    hdr.ar_name[0] = '/';
90 -  _bfd_ar_sizepad (hdr.ar_size, sizeof (hdr.ar_size), mapsize);
91 +  if (!_bfd_ar_sizepad (hdr.ar_size, sizeof (hdr.ar_size), mapsize))
92 +    return FALSE;
93    _bfd_ar_spacepad (hdr.ar_date, sizeof (hdr.ar_date), "%ld",
94                      ((arch->flags & BFD_DETERMINISTIC_OUTPUT) == 0
95                       ? time (NULL) : 0));
96 diff --git a/bfd/archive64.c b/bfd/archive64.c
97 index a906508..bdbda0a 100644
98 --- a/bfd/archive64.c
99 +++ b/bfd/archive64.c
100 @@ -169,8 +169,8 @@ bfd_elf64_archive_write_armap (bfd *arch,
101  
102    memset (&hdr, ' ', sizeof (struct ar_hdr));
103    memcpy (hdr.ar_name, "/SYM64/", strlen ("/SYM64/"));
104 -  _bfd_ar_sizepad (hdr.ar_size, sizeof (hdr.ar_size),
105 -                    mapsize);
106 +  if (!_bfd_ar_sizepad (hdr.ar_size, sizeof (hdr.ar_size), mapsize))
107 +    return FALSE;
108    _bfd_ar_spacepad (hdr.ar_date, sizeof (hdr.ar_date), "%ld",
109                      time (NULL));
110    /* This, at least, is what Intel coff sets the values to.: */
111 diff --git a/bfd/libbfd-in.h b/bfd/libbfd-in.h
112 index 57197ac..a4ba4b6 100644
113 --- a/bfd/libbfd-in.h
114 +++ b/bfd/libbfd-in.h
115 @@ -203,7 +203,7 @@ extern void *_bfd_generic_read_ar_hdr
116    (bfd *);
117  extern void _bfd_ar_spacepad
118    (char *, size_t, const char *, long);
119 -extern void _bfd_ar_sizepad
120 +extern int _bfd_ar_sizepad
121    (char *, size_t, bfd_size_type);
122  
123  extern void *_bfd_generic_read_ar_hdr_mag
124 diff --git a/bfd/libbfd.h b/bfd/libbfd.h
125 index 121e865..7f142d0 100644
126 --- a/bfd/libbfd.h
127 +++ b/bfd/libbfd.h
128 @@ -208,7 +208,7 @@ extern void *_bfd_generic_read_ar_hdr
129    (bfd *);
130  extern void _bfd_ar_spacepad
131    (char *, size_t, const char *, long);
132 -extern void _bfd_ar_sizepad
133 +extern int _bfd_ar_sizepad
134    (char *, size_t, bfd_size_type);
135  
136  extern void *_bfd_generic_read_ar_hdr_mag
137