This is the mail archive of the binutils-cvs@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb/binutils-2_29-branch] PR22245, Fix potential UB in bfd_set_error


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=99ca76d3db25af8e017d7d54df677db0561907f5

commit 99ca76d3db25af8e017d7d54df677db0561907f5
Author: Pavel I. Kryukov <kryukov@frtk.ru>
Date:   Tue Oct 3 22:42:07 2017 +0300

    PR22245, Fix potential UB in bfd_set_error
    
    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.
    
    (cherry picked from commit 9ba5f27cdd15d22d6c5739ff5d2b1c81d796e114)

Diff:
---
 bfd/ChangeLog | 7 +++++++
 bfd/bfd-in2.h | 2 +-
 bfd/bfd.c     | 4 ++--
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 8f8117d..65c9bab 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -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-09-28  Alan Modra  <amodra@gmail.com>
 
 	PR 22220
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index 1343780..0dba68b 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -7053,7 +7053,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);
 
diff --git a/bfd/bfd.c b/bfd/bfd.c
index 665f182..5da1a6f 100644
--- 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)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]