[PATCH] opcodes: Fix null pointer dereference vulnerability in pv_dup function
pengxu@kylinos.cn
pengxu@kylinos.cn
Fri Mar 27 07:36:25 GMT 2026
In opcodes/opc2c.c file, in the pv_dup() function, directly calling memcpy after malloc poses potential memory safety issues, with the following specific defects:
No check for malloc return value:
malloc may fail and return NULL. Calling memcpy on a NULL pointer results in undefined behavior (typically a segmentation fault).
A check for rv == NULL should be added:
if (rv == NULL)
return NULL;
---
opcodes/opc2c.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/opcodes/opc2c.c b/opcodes/opc2c.c
index 5e5fba67add..f66877fbcc4 100644
--- a/opcodes/opc2c.c
+++ b/opcodes/opc2c.c
@@ -462,6 +462,8 @@ pv_dup (char * p, char * ep)
{
int n = ep - p;
char *rv = (char *) malloc (n + 1);
+ if (rv == NULL)
+ return NULL;
memcpy (rv, p, n);
rv[n] = 0;
--
2.25.1
More information about the Binutils
mailing list