]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
PR22245, Fix potential UB in bfd_set_error
authorPavel I. Kryukov <kryukov@frtk.ru>
Tue, 3 Oct 2017 19:42:07 +0000 (22:42 +0300)
committerAlan Modra <amodra@gmail.com>
Wed, 4 Oct 2017 03:54:21 +0000 (14:24 +1030)
Passing enum as a first argument to variadic argument function
may lead to undefined behavior. The explanation on CERT site:
https://www.securecoding.cert.org/confluence/display/cplusplus/
EXP58-CPP.+Pass+an+object+of+the+correct+type+to+va_start

The bug was found by Kirill Nedostoev (nedostoev.ka@phystech.edu)
when he tried to build GNU binutils with Clang 7.

PR 22245
* bfd.c (bfd_set_error): Avoid UB on passing arg to va_start that
undergoes default promotion.
* bfd-in2.h: Regenerate.

bfd/ChangeLog
bfd/bfd-in2.h
bfd/bfd.c

index 9ef407c7c98f1aab6d8012af1997871ac7f3206e..ce948c8222efcd6fafb55ceb880f65d140e0a4a7 100644 (file)
@@ -1,3 +1,10 @@
+2017-10-04  Pavel I. Kryukov <kryukov@frtk.ru>
+
+       PR 22245
+       * bfd.c (bfd_set_error): Avoid UB on passing arg to va_start that
+       undergoes default promotion.
+       * bfd-in2.h: Regenerate.
+
 2017-10-02  Alan Modra  <amodra@gmail.com>
 
        * elf32-ppc.c (ppc_elf_relocate_section): Fix comment typo.
index d126aed086879ca46fd4801b9f98a22f5cb9a4cb..62be566e7535611c2826811666843f02a485a51a 100644 (file)
@@ -7054,7 +7054,7 @@ bfd_error_type;
 
 bfd_error_type bfd_get_error (void);
 
-void bfd_set_error (bfd_error_type error_tag, ...);
+void bfd_set_error (int error_tag, ...);
 
 const char *bfd_errmsg (bfd_error_type error_tag);
 
index 665f182559b37b4b9f61fdac19eb117badb9d0d8..5da1a6fd53a7024bd037913d77e5ab603e4ef8fd 100644 (file)
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -497,7 +497,7 @@ FUNCTION
        bfd_set_error
 
 SYNOPSIS
-       void bfd_set_error (bfd_error_type error_tag, ...);
+       void bfd_set_error (int error_tag, ...);
 
 DESCRIPTION
        Set the BFD error condition to be @var{error_tag}.
@@ -507,7 +507,7 @@ DESCRIPTION
 */
 
 void
-bfd_set_error (bfd_error_type error_tag, ...)
+bfd_set_error (int error_tag, ...)
 {
   bfd_error = error_tag;
   if (error_tag == bfd_error_on_input)