diff mbox series

[1/3] util: ensure decode_hex_own_buf is passed a valid buffer

Message ID 20241216102021.345566-1-absicsz@gmail.com (mailing list archive)
State Superseded
Headers show
Series [1/3] util: ensure decode_hex_own_buf is passed a valid buffer | expand

Commit Message

Sicelo Dec. 16, 2024, 10:19 a.m. UTC
---
 src/util.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Denis Kenzior Dec. 16, 2024, 8:26 p.m. UTC | #1
On 12/16/24 4:19 AM, Sicelo A. Mhlongo wrote:
> ---
>   src/util.c | 3 +++
>   1 file changed, 3 insertions(+)
> 

This set fails to compile:

Fedora (glibc) clang debug+sanitizers
=====================================
Configure: PASS
Build: FAIL
     drivers/atmodem/ussd.c:126:3: error: misleading indentation; statement is 
not part of the previous 'if' [-Werror,-Wmisleading-indentation]
       126 |                 goto out;
           |                 ^
     drivers/atmodem/ussd.c:124:2: note: previous statement is here
       124 |         if (strlen(content) > sizeof(msg) * 2)
           |         ^
     drivers/atmodem/ussd.c:97:23: error: unused variable 'msg_ptr' 
[-Werror,-Wunused-variable]
        97 |         const unsigned char *msg_ptr = NULL;
           |                              ^~~~~~~
     drivers/atmodem/ussd.c:98:7: error: unused variable 'msg_len' 
[-Werror,-Wunused-variable]
        98 |         long msg_len;
           |              ^~~~~~~
     drivers/atmodem/ussd.c:110:8: error: use of undeclared label 'out'
       110 |                 goto out;
           |                      ^
     drivers/atmodem/ussd.c:129:2: error: expected identifier or '('
       129 |         switch (charset) {
           |         ^
     drivers/atmodem/ussd.c:159:2: error: expected identifier or '('
       159 |         DBG("msg ptr %p msg len %ld", msg_ptr, msg_len);
           |         ^
     ./include/ofono/log.h:46:26: note: expanded from macro 'DBG'
        46 | #define DBG(fmt, arg...) do { \
           |                          ^
     drivers/atmodem/ussd.c:159:2: error: while loop outside of a function
     ./include/ofono/log.h:54:3: note: expanded from macro 'DBG'
        54 | } while (0)
           |   ^
     drivers/atmodem/ussd.c:161:1: error: type specifier missing, defaults to 
'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
       161 | out:
           | ^
           | int
     drivers/atmodem/ussd.c:161:4: error: expected ';' after top level declarator
       161 | out:
           |    ^
           |    ;
     drivers/atmodem/ussd.c:162:48: error: redefinition of parameter 'msg_ptr'
       162 |         ofono_ussd_notify(ussd, status, dcs, msg_ptr, msg_ptr ? 
msg_len : 0);
           |                                                       ^
     drivers/atmodem/ussd.c:162:56: error: expected ')'
       162 |         ofono_ussd_notify(ussd, status, dcs, msg_ptr, msg_ptr ? 
msg_len : 0);
           |                                                               ^
     drivers/atmodem/ussd.c:162:19: note: to match this '('
       162 |         ofono_ussd_notify(ussd, status, dcs, msg_ptr, msg_ptr ? 
msg_len : 0);
           |                          ^
     drivers/atmodem/ussd.c:162:2: error: type specifier missing, defaults to 
'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
       162 |         ofono_ussd_notify(ussd, status, dcs, msg_ptr, msg_ptr ? 
msg_len : 0);
           |         ^
           |         int
     drivers/atmodem/ussd.c:162:20: error: a parameter list without types is 
only allowed in a function definition
       162 |         ofono_ussd_notify(ussd, status, dcs, msg_ptr, msg_ptr ? 
msg_len : 0);
           |                           ^
     drivers/atmodem/ussd.c:163:1: error: extraneous closing brace ('}')
       163 | }
           | ^
     14 errors generated.
     make[1]: *** [Makefile:4083: drivers/atmodem/ussd.o] Error 1
     make[1]: Target 'all-am' not remade because of errors.
     make: *** [Makefile:2388: all] Error 2
diff mbox series

Patch

diff --git a/src/util.c b/src/util.c
index 53d55d7e..bfe46ef2 100644
--- a/src/util.c
+++ b/src/util.c
@@ -3181,6 +3181,9 @@  unsigned char *decode_hex_own_buf(const char *in, long len, long *items_written,
 	char c;
 	unsigned char b;
 
+	if (!buf)
+		return NULL;
+
 	if (len < 0)
 		len = strlen(in);