Przeglądaj źródła

core: use buffers instead of static empty string

- if code tries to write in, results in a crash
- reported by Juha Heinanen

(cherry picked from commit 6aa2b91b581d7e0f138a9a19f61d848caeb61a19)
Daniel-Constantin Mierla 8 lat temu
rodzic
commit
2705a9d364
2 zmienionych plików z 9 dodań i 6 usunięć
  1. 5 4
      src/core/lvalue.c
  2. 4 2
      src/core/parser/parse_uri.c

+ 5 - 4
src/core/lvalue.c

@@ -25,6 +25,9 @@
 #include "dprint.h"
 #include "route.h"
 
+static char _lval_empty_buf[2] = {0};
+static str _lval_empty = { _lval_empty_buf, 0 };
+
 /* callback to log assign actions */
 static log_assign_action_f _log_assign_action = NULL;
 
@@ -124,8 +127,7 @@ inline static int lval_avp_assign(struct run_act_ctx* h, struct sip_msg* msg,
 			flags=avp->type|AVP_VAL_STR;
 			v=run_select(&value.s, &rv->v.sel, msg);
 			if (unlikely(v!=0)){
-				value.s.s="";
-				value.s.len=0;
+				value.s = _lval_empty;
 				if (v<0){
 					ret=-1;
 					break;
@@ -302,8 +304,7 @@ inline static int lval_pvar_assign(struct run_act_ctx* h, struct sip_msg* msg,
 			v=run_select(&pval.rs, &rv->v.sel, msg);
 			if (unlikely(v!=0)){
 				pval.flags|=PV_VAL_EMPTY;
-				pval.rs.s="";
-				pval.rs.len=0;
+				pval.rs = _lval_empty;
 				if (v<0){
 					ret=-1;
 					break;

+ 4 - 2
src/core/parser/parse_uri.c

@@ -34,6 +34,9 @@
 #include "../error.h"
 #include "../core_stats.h"
 
+static char _sr_uri_empty_buf[2] = {0};
+static str _sr_uri_empty = { _sr_uri_empty_buf, 0 };
+
 /* buf= pointer to begining of uri (sip:[email protected]:5060;a=b?h=i)
  * len= len of uri
  * returns: fills uri & returns <0 on error or 0 if ok 
@@ -1191,8 +1194,7 @@ int parse_uri(char* buf, int len, struct sip_uri* uri)
 		case TELS_URI_T:
 			/* fix tel uris, move the number in uri and empty the host */
 			uri->user=uri->host;
-			uri->host.s="";
-			uri->host.len=0;
+			uri->host=_sr_uri_empty;
 			break;
 		/* urn: do nothing */
 		case URN_URI_T: