All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Free converted string after use.
@ 2009-10-16 17:44 Andrzej Zaborowski
  2009-10-16 18:22 ` Denis Kenzior
  0 siblings, 1 reply; 2+ messages in thread
From: Andrzej Zaborowski @ 2009-10-16 17:44 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1230 bytes --]

Also make sure we don't read beyond end of the string.
---
 drivers/atmodem/ussd.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/atmodem/ussd.c b/drivers/atmodem/ussd.c
index c29f8f6..1d819a3 100644
--- a/drivers/atmodem/ussd.c
+++ b/drivers/atmodem/ussd.c
@@ -59,7 +59,7 @@ static void at_ussd_request(struct ofono_ussd *ussd, const char *str,
 {
 	GAtChat *chat = ofono_ussd_get_data(ussd);
 	struct cb_data *cbd = cb_data_new(cb, data);
-	unsigned char *converted;
+	unsigned char *converted = NULL;
 	int dcs;
 	int max_len;
 	long written;
@@ -83,7 +83,10 @@ static void at_ussd_request(struct ofono_ussd *ussd, const char *str,
 	if (written > max_len)
 		goto error;
 
-	sprintf(buf, "AT+CUSD=1,\"%s\",%d", converted, dcs);
+	sprintf(buf, "AT+CUSD=1,\"%*s\",%d", (int) written, converted, dcs);
+
+	g_free(converted);
+	converted = NULL;
 
 	if (g_at_chat_send(chat, buf, none_prefix,
 				cusd_request_cb, cbd, g_free) > 0)
@@ -92,6 +95,8 @@ static void at_ussd_request(struct ofono_ussd *ussd, const char *str,
 error:
 	if (cbd)
 		g_free(cbd);
+	if (converted)
+		g_free(converted);
 
 	CALLBACK_WITH_FAILURE(cb, data);
 }
-- 
1.6.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-10-16 18:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-16 17:44 [PATCH] Free converted string after use Andrzej Zaborowski
2009-10-16 18:22 ` Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.