This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH 4/7] Fix int overflow
- From: Mikhail Maltsev <maltsevm at gmail dot com>
- To: gcc-patches <gcc-patches at gnu dot org>, Jason Merrill <jason at redhat dot com>
- Date: Mon, 06 Jul 2015 22:36:42 +0300
- Subject: [PATCH 4/7] Fix int overflow
- Authentication-results: sourceware.org; auth=none
- References: <559AD66D dot 1070809 at gmail dot com>
---
libiberty/cp-demangle.c | 3 ++-
libiberty/testsuite/demangle-expected | 4 ++++
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c
index 44a0a9b..befa6b6 100644
--- a/libiberty/cp-demangle.c
+++ b/libiberty/cp-demangle.c
@@ -103,6 +103,7 @@
#include "config.h"
#endif
+#include <limits.h>
#include <stdio.h>
#ifdef HAVE_STDLIB_H
@@ -1599,7 +1600,7 @@ d_source_name (struct d_info *di)
struct demangle_component *ret;
len = d_number (di);
- if (len <= 0)
+ if (len <= 0 || len > INT_MAX)
return NULL;
ret = d_identifier (di, len);
di->last_name = ret;
diff --git a/libiberty/testsuite/demangle-expected
b/libiberty/testsuite/demangle-expected
index 47ca8f5..9a8d3db 100644
--- a/libiberty/testsuite/demangle-expected
+++ b/libiberty/testsuite/demangle-expected
@@ -4096,6 +4096,10 @@ std::complex<int>::real[abi:cxx11]() const
--format=gnu-v3
Av32_f
Av32_f
+# Check range when converting from long to int
+--format=gnu-v3
+_Z11111111111
+_Z11111111111
#
# Ada (GNAT) tests.
#
--
1.8.3.1