summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/binutils/binutils/0002-CVE-2021-20197.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-devtools/binutils/binutils/0002-CVE-2021-20197.patch')
-rw-r--r--meta/recipes-devtools/binutils/binutils/0002-CVE-2021-20197.patch170
1 files changed, 0 insertions, 170 deletions
diff --git a/meta/recipes-devtools/binutils/binutils/0002-CVE-2021-20197.patch b/meta/recipes-devtools/binutils/binutils/0002-CVE-2021-20197.patch
deleted file mode 100644
index 3771f571eb..0000000000
--- a/meta/recipes-devtools/binutils/binutils/0002-CVE-2021-20197.patch
+++ /dev/null
@@ -1,170 +0,0 @@
1From d3edaa91d4cf7202ec14342410194841e2f67f12 Mon Sep 17 00:00:00 2001
2From: Alan Modra <amodra@gmail.com>
3Date: Fri, 26 Feb 2021 11:30:32 +1030
4Subject: [PATCH] Reinstate various pieces backed out from smart_rename changes
5
6In the interests of a stable release various last minute smart_rename
7patches were backed out of the 2.36 branch. The main reason to
8reinstate some of those backed out changes here is to make necessary
9followup fixes to commit 8e03235147a9 simple cherry-picks from
10mainline. A secondary reason is that ar -M support isn't fixed for
11pr26945 without this patch.
12
13 PR 26945
14 * ar.c: Don't include libbfd.h.
15 (write_archive): Replace xmalloc+strcpy with xstrdup.
16 * arsup.c (temp_name, real_ofd): New static variables.
17 (ar_open): Use make_tempname and bfd_fdopenw.
18 (ar_save): Adjust to suit ar_open changes.
19 * objcopy.c: Don't include libbfd.h.
20 * rename.c: Rename and reorder variables.
21
22(cherry picked from commit 95b91a043aeaeb546d2fea556d84a2de1e917770)
23
24Upstream-Status: Backport [https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d3edaa91d4cf7202ec14342410194841e2f67f12]
25CVE: CVE-2021-20197
26Signed-off-by: Vinay Kumar <vinay.m.engg@gmail.com>
27---
28 binutils/ar.c | 4 +---
29 binutils/arsup.c | 37 +++++++++++++++++++++++++------------
30 binutils/objcopy.c | 1 -
31 binutils/rename.c | 6 +++---
32 5 files changed, 42 insertions(+), 19 deletions(-)
33
34diff --git a/binutils/ar.c b/binutils/ar.c
35index 3a91708b51c..44df48c5c67 100644
36--- a/binutils/ar.c
37+++ b/binutils/ar.c
38@@ -25,7 +25,6 @@
39
40 #include "sysdep.h"
41 #include "bfd.h"
42-#include "libbfd.h"
43 #include "libiberty.h"
44 #include "progress.h"
45 #include "getopt.h"
46@@ -1255,8 +1254,7 @@ write_archive (bfd *iarch)
47 bfd *contents_head = iarch->archive_next;
48 int ofd = -1;
49
50- old_name = (char *) xmalloc (strlen (bfd_get_filename (iarch)) + 1);
51- strcpy (old_name, bfd_get_filename (iarch));
52+ old_name = xstrdup (bfd_get_filename (iarch));
53 new_name = make_tempname (old_name, &ofd);
54
55 if (new_name == NULL)
56diff --git a/binutils/arsup.c b/binutils/arsup.c
57index 0a1f63f6456..f7ce8f0bc82 100644
58--- a/binutils/arsup.c
59+++ b/binutils/arsup.c
60@@ -42,6 +42,8 @@ extern int deterministic;
61
62 static bfd *obfd;
63 static char *real_name;
64+static char *temp_name;
65+static int real_ofd;
66 static FILE *outfile;
67
68 static void
69@@ -149,27 +151,24 @@ maybequit (void)
70 void
71 ar_open (char *name, int t)
72 {
73- char *tname;
74- const char *bname = lbasename (name);
75- real_name = name;
76+ real_name = xstrdup (name);
77+ temp_name = make_tempname (real_name, &real_ofd);
78
79- /* Prepend tmp- to the beginning, to avoid file-name clashes after
80- truncation on filesystems with limited namespaces (DOS). */
81- if (asprintf (&tname, "%.*stmp-%s", (int) (bname - name), name, bname) == -1)
82+ if (temp_name == NULL)
83 {
84- fprintf (stderr, _("%s: Can't allocate memory for temp name (%s)\n"),
85+ fprintf (stderr, _("%s: Can't open temporary file (%s)\n"),
86 program_name, strerror(errno));
87 maybequit ();
88 return;
89 }
90
91- obfd = bfd_openw (tname, NULL);
92+ obfd = bfd_fdopenw (temp_name, NULL, real_ofd);
93
94 if (!obfd)
95 {
96 fprintf (stderr,
97 _("%s: Can't open output archive %s\n"),
98- program_name, tname);
99+ program_name, temp_name);
100
101 maybequit ();
102 }
103@@ -344,16 +343,30 @@ ar_save (void)
104 }
105 else
106 {
107- char *ofilename = xstrdup (bfd_get_filename (obfd));
108+ struct stat target_stat;
109
110 if (deterministic > 0)
111 obfd->flags |= BFD_DETERMINISTIC_OUTPUT;
112
113 bfd_close (obfd);
114
115- smart_rename (ofilename, real_name, NULL);
116+ if (stat (real_name, &target_stat) != 0)
117+ {
118+ /* The temp file created in ar_open has mode 0600 as per mkstemp.
119+ Create the real empty output file here so smart_rename will
120+ update the mode according to the process umask. */
121+ obfd = bfd_openw (real_name, NULL);
122+ if (obfd != NULL)
123+ {
124+ bfd_set_format (obfd, bfd_archive);
125+ bfd_close (obfd);
126+ }
127+ }
128+
129+ smart_rename (temp_name, real_name, NULL);
130 obfd = 0;
131- free (ofilename);
132+ free (temp_name);
133+ free (real_name);
134 }
135 }
136
137diff --git a/binutils/objcopy.c b/binutils/objcopy.c
138index 07a872b5a80..73aa8bc2514 100644
139--- a/binutils/objcopy.c
140+++ b/binutils/objcopy.c
141@@ -20,7 +20,6 @@
142
143 #include "sysdep.h"
144 #include "bfd.h"
145-#include "libbfd.h"
146 #include "progress.h"
147 #include "getopt.h"
148 #include "libiberty.h"
149diff --git a/binutils/rename.c b/binutils/rename.c
150index f471b45fd3f..2ff092ee22b 100644
151--- a/binutils/rename.c
152+++ b/binutils/rename.c
153@@ -130,11 +130,11 @@ int
154 smart_rename (const char *from, const char *to,
155 struct stat *target_stat ATTRIBUTE_UNUSED)
156 {
157- bfd_boolean exists;
158- struct stat s;
159 int ret = 0;
160+ struct stat to_stat;
161+ bfd_boolean exists;
162
163- exists = lstat (to, &s) == 0;
164+ exists = lstat (to, &to_stat) == 0;
165
166 #if defined (_WIN32) && !defined (__CYGWIN32__)
167 /* Win32, unlike unix, will not erase `to' in `rename(from, to)' but
168--
1692.31.1
170