[sr-dev] git:sr_3.0: presence(k): fix off-by-one memory allocation

Andrei Pelinescu-Onciul andrei at iptel.org
Mon Nov 30 12:37:55 CET 2009


Module: sip-router
Branch: sr_3.0
Commit: 229bd1f517cb9177dc731929c31153b2b9513215
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=229bd1f517cb9177dc731929c31153b2b9513215

Author: Andrei Pelinescu-Onciul <andrei at iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei at iptel.org>
Date:   Mon Nov 30 12:29:20 2009 +0100

presence(k): fix off-by-one memory allocation

Due to some missing '()' ( (...)?resource.len:event.len + 1
instead of ((...)?resource.len:event.len) + 1 ) sometimes the
memory allocated was less with one byte then what was needed.
The fixed version also replaces ?: with MAX_unsigned() (does the
same thing and it's easier to read).

Reported-by: Andres Moya  andres.moya.i gmail com

---

 modules_k/presence/notify.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/modules_k/presence/notify.c b/modules_k/presence/notify.c
index 92c2f55..6d16033 100644
--- a/modules_k/presence/notify.c
+++ b/modules_k/presence/notify.c
@@ -1793,8 +1793,7 @@ str* create_winfo_xml(watcher_t* watchers, char* version,
 		LM_ERR("while adding child\n");
 		goto error;
 	}
-	res= (char*)pkg_malloc((resource.len>event.len)?resource.len:event.len
-			+ 1);
+	res= (char*)pkg_malloc(MAX_unsigned(resource.len, event.len) + 1);
 	if(res== NULL)
 	{
 		ERR_MEM(PKG_MEM_STR);




More information about the sr-dev mailing list