Fix another sdp-xml bug
PATCH 1/1 Fix another sdp-xml bug
Spotted by Luiz, another invalid memory access when trying to read past the end of a string that's not nul-terminated.
strndup to the rescue.
Cheers
Quoted 1 line
From
48ca11b62344c1af17e16ddec0fad727042a4b03Mon Sep 17 00:00:00 2001
From: Bastien Nocera <[email protected]>
Date: Tue, 24 Mar 2009 11:46:18 +0000
Subject: [PATCH] Fix invalid memory access when dealing with URLs
Just like strings attributes, URLs might not be NUL-terminated. Make sure we don't read past the end of the allocated memory when copying them.
--- common/sdp-xml.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)
common/sdp-xml.c +8 -1
@@ -25,6 +25,7 @@#include <config.h> #endif +#define _GNU_SOURCE#include <stdio.h> #include <errno.h> #include <ctype.h>
@@ -323,11 +324,17 @@ static void convert_raw_data_to_xml(sdp_data_t *value, int indent_level,case SDP_URL_STR8 :case SDP_URL_STR16 :case SDP_URL_STR32 : + { +char *strBuf; +appender (data, indent);appender (data,"<url value=\"" ); -appender (data, value->val.str); + strBuf =strndup (value->val.str, value->unitSize); +appender (data, strBuf); +free (strBuf);appender (data,"\" />\n" );break ; + }case SDP_SEQ8 :case SDP_SEQ16 :
Signature · 1 line
1.6.0.6
Quoted 4 lines · Bastien Nocera
Spotted by Luiz, another invalid memory access when trying to read past the end of a string that's not nul-terminated.
strndup to the rescue.
Never mind, previous patch was off by one. Corrected patch attached.
Quoted 1 line
From
0606404a81cc73e7a1ee90da9641a6a87c8f6f43Mon Sep 17 00:00:00 2001
From: Bastien Nocera <[email protected]>
Date: Tue, 24 Mar 2009 11:46:18 +0000
Subject: [PATCH] Fix invalid memory access when dealing with URLs
Just like strings attributes, URLs might not be NUL-terminated. Make sure we don't read past the end of the allocated memory when copying them.
--- common/sdp-xml.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)
common/sdp-xml.c +8 -1
@@ -25,6 +25,7 @@#include <config.h> #endif +#define _GNU_SOURCE#include <stdio.h> #include <errno.h> #include <ctype.h>
@@ -323,11 +324,17 @@ static void convert_raw_data_to_xml(sdp_data_t *value, int indent_level,case SDP_URL_STR8 :case SDP_URL_STR16 :case SDP_URL_STR32 : + { +char *strBuf; +appender (data, indent);appender (data,"<url value=\"" ); -appender (data, value->val.str); + strBuf =strndup (value->val.str, value->unitSize -1 ); +appender (data, strBuf); +free (strBuf);appender (data,"\" />\n" );break ; + }case SDP_SEQ8 :case SDP_SEQ16 :
Signature · 1 line
1.6.0.6
Hi,
Quoted 1 line · Bastien Nocera
Never mind, previous patch was off by one. Corrected patch attached.
I already pushed the first one and fixed this issue myself in a second commit.
Johan
Hi Bastien,
Quoted 4 lines · Bastien Nocera
Spotted by Luiz, another invalid memory access when trying to read past the end of a string that's not nul-terminated.
strndup to the rescue.
Thanks! Pushed upstream.
Johan