Skip to contentSkip to conversation

util: ensure decode_hex_own_buf is passed a valid buffer

PATCH Superseded Sicelo A. Mhlongo 2 participants 4 messages Dec 16, 2024

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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

---
 src/util.c | 3 +++
 1 file changed, 3 insertions(+)
src/util.c +3 -0
index 53d55d7e..bfe46ef2 100644
@@ -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);
 
Signature · 1 line
2.45.2
#1 lore raw

PATCH 2/3 atmodem: ussd: ensure ussd content fits in buffer

Fixes CVE-2024-7539
---
 drivers/atmodem/ussd.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/atmodem/ussd.c +5 -0
index 32a9fe91..775c74d1 100644
@@ -121,6 +121,11 @@ static void cusd_parse(GAtResult *result, struct ofono_ussd *ussd)
 
 	DBG("response charset %d modem charset %d", charset, data->charset);
 
+	if (strlen(content) > sizeof(msg) * 2)
+		status = 4; /* Not supported */
+		goto out;
+	}
+
 	switch (charset) {
 	case SMS_CHARSET_7BIT:
 		switch (data->charset) {
Signature · 1 line
2.45.2
#2 lore raw

PATCH 3/3 atmodem: sms: ensure buffer is initialized before use

In reply to Sicelo A. Mhlongo
Fixes CVE-2024-7540
Fixes CVE-2024-7541
Fixes CVE-2024-7542
---
 drivers/atmodem/sms.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/atmodem/sms.c +3 -3
index d994856b..0668c631 100644
@@ -399,7 +399,7 @@ static void at_cmt_notify(GAtResult *result, gpointer user_data)
 	struct sms_data *data = ofono_sms_get_data(sms);
 	GAtResultIter iter;
 	const char *hexpdu;
-	unsigned char pdu[176];
+	unsigned char pdu[176] = {0};
 	long pdu_len;
 	int tpdu_len;
 
@@ -466,7 +466,7 @@ static void at_cmgr_notify(GAtResult *result, gpointer user_data)
 	struct sms_data *data = ofono_sms_get_data(sms);
 	GAtResultIter iter;
 	const char *hexpdu;
-	unsigned char pdu[176];
+	unsigned char pdu[176] = {0};
 	long pdu_len;
 	int tpdu_len;
 
@@ -648,7 +648,7 @@ static void at_cmgl_notify(GAtResult *result, gpointer user_data)
 	struct sms_data *data = ofono_sms_get_data(sms);
 	GAtResultIter iter;
 	const char *hexpdu;
-	unsigned char pdu[176];
+	unsigned char pdu[176] = {0};
 	long pdu_len;
 	int tpdu_len;
 	int index;
Signature · 1 line
2.45.2
#3 lore raw
In reply to Sicelo A. Mhlongo
Quoted 4 lines · Sicelo A. Mhlongo
---
  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