Fix issues found with static analyzer
cover Fix issues found with static analyzer
From: Denis Grigorev <[email protected]>
This patch series fixes several minor issues found with SVACE static analyzer.
Denis Grigorev (6):
phonebook: Fix potential buffer overflow
stemodem: Fix buffer size allocated for rtnl_msg
sms: Fix buffer size allocated for SMS PDU
atmodem: Fix potential buffer overflow
emulator: Avoid potential null dereference
voicecall: Avoid potential double free
drivers/atmodem/sim.c | 2 +- drivers/atmodem/sms.c | 2 +- drivers/stemodem/caif_rtnl.c | 5 +++-- src/emulator.c | 3 ++- src/phonebook.c | 2 +- src/stkutil.c | 2 +- src/voicecall.c | 3 --- 7 files changed, 9 insertions(+), 10 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/6 phonebook: Fix potential buffer overflow
From: Denis Grigorev <[email protected]>
This fixes possible access to an address outside of dest if src is greater than or equal to 128 bytes.
--- src/phonebook.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/phonebook.c +1 -1
@@ -112,7 +112,7 @@ static void add_slash(char *dest, const char *src, int len_max, int len) {int i, j; -for (i =0 , j =0 ; i < len && j < len_max; i++, j++) { +for (i =0 , j =0 ; i < len && j < len_max -1 ; i++, j++) {switch (src[i]) {case '\n' : dest[j++] ='\\' ;
Signature · 1 line
2.17.1
PATCH 2/6 stemodem: Fix buffer size allocated for rtnl_msg
In reply to [email protected]From: Denis Grigorev <[email protected]>
--- drivers/stemodem/caif_rtnl.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/stemodem/caif_rtnl.c +3 -2
@@ -41,12 +41,13 @@#define NLMSG_TAIL (nmsg) \ ((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len))) -#define RTNL_MSG_SIZE 1024 +#define RTNL_DATA_SIZE 1024 +#define RTNL_MSG_SIZE sizeof(struct rtnl_msg)struct rtnl_msg {struct nlmsghdr n;struct ifinfomsg i; -char data[RTNL_MSG_SIZE ]; +char data[RTNL_DATA_SIZE ]; };struct iplink_req {
Signature · 1 line
2.17.1
PATCH 3/6 sms: Fix buffer size allocated for SMS PDU
In reply to [email protected]From: Denis Grigorev <[email protected]>
According to the comment for sms_encode() the buffer size must be at least 164 (tpdu) + 12 (SC address).
--- drivers/atmodem/sms.c | 2 +- src/stkutil.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/atmodem/sms.c +1 -1
@@ -919,7 +919,7 @@ static gboolean build_cnmi_string(char *buf, int *cnmi_opts,static void construct_ack_pdu (struct sms_data *d) {struct sms ackpdu; -unsigned char pdu[164 ]; +unsigned char pdu[176 ];int len;int tpdu_len;
src/stkutil.c +1 -1
@@ -4244,7 +4244,7 @@ static bool build_dataobj_gsm_sms_tpdu(struct stk_tlv_builder *tlv,const struct sms_deliver *msg = data;struct sms sms;uint8_t tag =STK_DATA_OBJECT_TYPE_GSM_SMS_TPDU ; -uint8_t tpdu[165 ]; +uint8_t tpdu[176 ];int tpdu_len; sms.type =SMS_TYPE_DELIVER ;
Signature · 1 line
2.17.1
PATCH 4/6 atmodem: Fix potential buffer overflow
In reply to [email protected]From: Denis Grigorev <[email protected]>
The type of the session_id variable is int, so cmd could potentially overflow if the session_id is large enough.
--- drivers/atmodem/sim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/atmodem/sim.c +1 -1
@@ -1724,7 +1724,7 @@ static void at_close_channel(struct ofono_sim *sim, int session_id, {struct sim_data *sd =ofono_sim_get_data (sim);struct cb_data *cbd =cb_data_new (cb, data); -char cmd[15 ]; +char cmd[32 ];sprintf (cmd,"AT+CCHC=%d" , session_id);
Signature · 1 line
2.17.1
PATCH 5/6 emulator: Avoid potential null dereference
In reply to [email protected]From: Denis Grigorev <[email protected]>
--- src/emulator.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
src/emulator.c +2 -1
@@ -1700,7 +1700,8 @@ int ofono_emulator_start_codec_negotiation(struct ofono_emulator *em,* Report we're done even if we don't have done any * negotiation as the other side may have to clean up. */ -cb (0 , data); +if (cb) +cb (0 , data);/* * If we didn't received any +BAC during the SLC setup the
Signature · 1 line
2.17.1
PATCH 6/6 voicecall: Avoid potential double free
In reply to [email protected]From: Denis Grigorev <[email protected]>
There's no need to free the memory pointed by v, since it is already freed in voicecall_dbus_register() or v is null.
--- src/voicecall.c | 3 --- 1 file changed, 3 deletions(-)
src/voicecall.c +0 -3
@@ -2478,9 +2478,6 @@ void ofono_voicecall_notify(struct ofono_voicecall *vc, error:if (newcall)g_free (newcall); - -if (v) -g_free (v); }void ofono_voicecall_mpty_hint (struct ofono_voicecall *vc,unsigned int ids)
Signature · 1 line
2.17.1