summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/elfutils/elfutils-0.166/0001-ar-Fix-GCC7-Wformat-length-issues.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-devtools/elfutils/elfutils-0.166/0001-ar-Fix-GCC7-Wformat-length-issues.patch')
-rw-r--r--meta/recipes-devtools/elfutils/elfutils-0.166/0001-ar-Fix-GCC7-Wformat-length-issues.patch125
1 files changed, 125 insertions, 0 deletions
diff --git a/meta/recipes-devtools/elfutils/elfutils-0.166/0001-ar-Fix-GCC7-Wformat-length-issues.patch b/meta/recipes-devtools/elfutils/elfutils-0.166/0001-ar-Fix-GCC7-Wformat-length-issues.patch
new file mode 100644
index 0000000000..3465476784
--- /dev/null
+++ b/meta/recipes-devtools/elfutils/elfutils-0.166/0001-ar-Fix-GCC7-Wformat-length-issues.patch
@@ -0,0 +1,125 @@
1From f090883ca61f0bf0f979c5b26d4e1a69e805156e Mon Sep 17 00:00:00 2001
2From: Mark Wielaard <mjw@redhat.com>
3Date: Thu, 10 Nov 2016 18:45:02 +0100
4Subject: [PATCH] ar: Fix GCC7 -Wformat-length issues.
5
6GCC7 adds warnings for snprintf formatting into too small buffers.
7Fix the two issues pointed out by the new warning. The ar header
8fields are fixed length containing left-justified strings without
9zero terminator. snprintf always adds a '\0' char at the end (which
10we then don't copy into the ar header field) and numbers are decimal
11strings of fixed 10 chars (-Wformat-length thinks formatting
12them as size_t might overflow the buffer on 64bit arches).
13
14Signed-off-by: Mark Wielaard <mjw@redhat.com>
15
16Upstream-Status: Backport
17Upstream-Commit: d5afff85e22b38949f3e7936231c67de16e180e8
18---
19 src/ar.c | 15 +++++++++++----
20 src/arlib.c | 16 ++++++++++------
21 2 files changed, 21 insertions(+), 10 deletions(-)
22
23diff --git a/src/ar.c b/src/ar.c
24index 1320d07b..f2160d35 100644
25--- a/src/ar.c
26+++ b/src/ar.c
27@@ -1,5 +1,5 @@
28 /* Create, modify, and extract from archives.
29- Copyright (C) 2005-2012 Red Hat, Inc.
30+ Copyright (C) 2005-2012, 2016 Red Hat, Inc.
31 This file is part of elfutils.
32 Written by Ulrich Drepper <drepper@redhat.com>, 2005.
33
34@@ -853,7 +853,10 @@ write_member (struct armem *memb, off_t *startp, off_t *lenp, Elf *elf,
35 off_t end_off, int newfd)
36 {
37 struct ar_hdr arhdr;
38- char tmpbuf[sizeof (arhdr.ar_name) + 1];
39+ /* The ar_name is not actually zero teminated, but we need that for
40+ snprintf. Also if the name is too long, then the string starts
41+ with '/' plus an index off number (decimal). */
42+ char tmpbuf[sizeof (arhdr.ar_name) + 2];
43
44 bool changed_header = memb->long_name_off != -1;
45 if (changed_header)
46@@ -1455,7 +1458,11 @@ do_oper_insert (int oper, const char *arfname, char **argv, int argc,
47
48 /* Create the header. */
49 struct ar_hdr arhdr;
50- char tmpbuf[sizeof (arhdr.ar_name) + 1];
51+ /* The ar_name is not actually zero teminated, but we
52+ need that for snprintf. Also if the name is too
53+ long, then the string starts with '/' plus an index
54+ off number (decimal). */
55+ char tmpbuf[sizeof (arhdr.ar_name) + 2];
56 if (all->long_name_off == -1)
57 {
58 size_t namelen = strlen (all->name);
59@@ -1465,7 +1472,7 @@ do_oper_insert (int oper, const char *arfname, char **argv, int argc,
60 }
61 else
62 {
63- snprintf (tmpbuf, sizeof (arhdr.ar_name) + 1, "/%-*ld",
64+ snprintf (tmpbuf, sizeof (tmpbuf), "/%-*ld",
65 (int) sizeof (arhdr.ar_name), all->long_name_off);
66 memcpy (arhdr.ar_name, tmpbuf, sizeof (arhdr.ar_name));
67 }
68diff --git a/src/arlib.c b/src/arlib.c
69index 43a9145b..0c2e4cde 100644
70--- a/src/arlib.c
71+++ b/src/arlib.c
72@@ -1,5 +1,5 @@
73 /* Functions to handle creation of Linux archives.
74- Copyright (C) 2007-2012 Red Hat, Inc.
75+ Copyright (C) 2007-2012, 2016 Red Hat, Inc.
76 This file is part of elfutils.
77 Written by Ulrich Drepper <drepper@redhat.com>, 2007.
78
79@@ -23,6 +23,7 @@
80 #include <assert.h>
81 #include <error.h>
82 #include <gelf.h>
83+#include <inttypes.h>
84 #include <libintl.h>
85 #include <stdio.h>
86 #include <stdlib.h>
87@@ -107,6 +108,9 @@ arlib_init (void)
88 void
89 arlib_finalize (void)
90 {
91+ /* Note that the size is stored as decimal string in 10 chars,
92+ without zero terminator (we add + 1 here only so snprintf can
93+ put it at the end, we then don't use it when we memcpy it). */
94 char tmpbuf[sizeof (((struct ar_hdr *) NULL)->ar_size) + 1];
95
96 symtab.longnameslen = obstack_object_size (&symtab.longnamesob);
97@@ -121,9 +125,9 @@ arlib_finalize (void)
98
99 symtab.longnames = obstack_finish (&symtab.longnamesob);
100
101- int s = snprintf (tmpbuf, sizeof (tmpbuf), "%-*zu",
102+ int s = snprintf (tmpbuf, sizeof (tmpbuf), "%-*" PRIu32 "",
103 (int) sizeof (((struct ar_hdr *) NULL)->ar_size),
104- symtab.longnameslen - sizeof (struct ar_hdr));
105+ (uint32_t) (symtab.longnameslen - sizeof (struct ar_hdr)));
106 memcpy (&((struct ar_hdr *) symtab.longnames)->ar_size, tmpbuf, s);
107 }
108
109@@ -169,10 +173,10 @@ arlib_finalize (void)
110
111 /* See comment for ar_date above. */
112 memcpy (&((struct ar_hdr *) symtab.symsoff)->ar_size, tmpbuf,
113- snprintf (tmpbuf, sizeof (tmpbuf), "%-*zu",
114+ snprintf (tmpbuf, sizeof (tmpbuf), "%-*" PRIu32 "",
115 (int) sizeof (((struct ar_hdr *) NULL)->ar_size),
116- symtab.symsofflen + symtab.symsnamelen
117- - sizeof (struct ar_hdr)));
118+ (uint32_t) (symtab.symsofflen + symtab.symsnamelen
119+ - sizeof (struct ar_hdr))));
120 }
121
122
123--
1242.13.0
125