[PATCH] libiberty: prevent null dereferencing on dlang_type
Luís Ferreira
contact@lsferreira.net
Wed Sep 22 01:31:03 GMT 2021
This patch prevents dereferencing a null reference on a crafted
malformed magled name, often causing SIGSEGV to be raised.
Signed-off-by: Luís Ferreira <contact@lsferreira.net>
---
libiberty/d-demangle.c | 2 +-
libiberty/testsuite/d-demangle-expected | 5 ++++-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/libiberty/d-demangle.c b/libiberty/d-demangle.c
index a2152cc65518..469398261994 100644
--- a/libiberty/d-demangle.c
+++ b/libiberty/d-demangle.c
@@ -875,7 +875,7 @@ dlang_type (string *decl, const char *mangled,
struct dlang_info *info)
szmods = string_length (&mods);
/* Back referenced function type. */
- if (*mangled == 'Q')
+ if (mangled && *mangled == 'Q')
mangled = dlang_type_backref (decl, mangled, info, 1);
else
mangled = dlang_function_type (decl, mangled, info);
diff --git a/libiberty/testsuite/d-demangle-expected
b/libiberty/testsuite/d-demangle-expected
index c35185c3e1e3..799f4724b72e 100644
--- a/libiberty/testsuite/d-demangle-expected
+++ b/libiberty/testsuite/d-demangle-expected
@@ -991,11 +991,14 @@ _D88
_D5__T1aZv
_D5__T1aZv
#
---format=dlang
_D00
_D00
#
--format=dlang
+_D01_D
+_D01_D
+#
+--format=dlang
_D9223372036854775817
_D9223372036854775817
#
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20210922/ddbe2770/attachment.sig>
More information about the Gcc-patches
mailing list