[sr-dev] git:master:82acaac1: ctl: handle null string value in rpc response

Daniel-Constantin Mierla miconda at gmail.com
Fri Jan 6 08:43:04 CET 2017


Module: kamailio
Branch: master
Commit: 82acaac1baceac4b2c81ecd70591021497a725b7
URL: https://github.com/kamailio/kamailio/commit/82acaac1baceac4b2c81ecd70591021497a725b7

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2017-01-06T08:42:16+01:00

ctl: handle null string value in rpc response

---

Modified: src/modules/ctl/binrpc.h
Modified: src/modules/ctl/binrpc_run.c

---

Diff:  https://github.com/kamailio/kamailio/commit/82acaac1baceac4b2c81ecd70591021497a725b7.diff
Patch: https://github.com/kamailio/kamailio/commit/82acaac1baceac4b2c81ecd70591021497a725b7.patch

---

diff --git a/src/modules/ctl/binrpc.h b/src/modules/ctl/binrpc.h
index cee48e2..2e33a39 100644
--- a/src/modules/ctl/binrpc.h
+++ b/src/modules/ctl/binrpc.h
@@ -359,7 +359,7 @@ inline static int binrpc_add_int_type(struct binrpc_pkt* pkt, int i, int type)
  */
 inline static int binrpc_add_skip(struct binrpc_pkt* pkt, int bytes)
 {
-	
+
 	if ((pkt->crt+bytes)>=pkt->end)
 		return E_BINRPC_OVERFLOW;
 	pkt->crt+=bytes;
@@ -373,7 +373,7 @@ inline static int binrpc_add_skip(struct binrpc_pkt* pkt, int bytes)
  * manually later (and also use binrpc_add_skip(pkt, l) or increase
  *  pkt->crt directly if you want to continue adding to this pkt).
  *  Usefull for optimizing str writing (e.g. writev(iovec))
- *  WARNING: use with care, low level function, binrpc_addstr or 
+ *  WARNING: use with care, low level function, binrpc_addstr or
  *           binrpc_add_str_type are probably what you want.
  *  WARNING1: BINRPC_T_STR and BINRPC_T_AVP must be  0 term, the len passed to
  *            this function, must include the \0 in this case.
@@ -383,7 +383,7 @@ inline static int binrpc_add_str_mark(struct binrpc_pkt* pkt, int type,
 {
 	int size;
 	unsigned char* p;
-	
+
 	if (pkt->crt>=pkt->end) goto error_len;
 	if (l<8){
 		size=l;
@@ -410,7 +410,7 @@ inline static int binrpc_add_str_type(struct binrpc_pkt* pkt, char* s, int len,
 	int l;
 	int zero_term; /* whether or not to add an extra 0 at the end */
 	unsigned char* p;
-	
+
 	zero_term=((type==BINRPC_T_STR)||(type==BINRPC_T_AVP));
 	l=len+zero_term;
 	if (l<8){
@@ -439,7 +439,7 @@ inline static int binrpc_addavp(struct binrpc_pkt* pkt, struct binrpc_val* avp)
 {
 	int ret;
 	unsigned char* bak;
-	
+
 	bak=pkt->crt;
 	ret=binrpc_add_str_type(pkt, avp->name.s, avp->name.len, BINRPC_T_AVP);
 	if (ret<0) return ret;
@@ -449,7 +449,7 @@ inline static int binrpc_addavp(struct binrpc_pkt* pkt, struct binrpc_val* avp)
 			break;
 		case BINRPC_T_STR:
 		case BINRPC_T_BYTES:
-			ret=binrpc_add_str_type(pkt, avp->u.strval.s, 
+			ret=binrpc_add_str_type(pkt, avp->u.strval.s,
 										avp->u.strval.len,
 										avp->type);
 			break;
@@ -457,7 +457,7 @@ inline static int binrpc_addavp(struct binrpc_pkt* pkt, struct binrpc_val* avp)
 		case BINRPC_T_ARRAY:
 			ret=binrpc_add_tag(pkt, avp->type, 0);
 			break;
-		case BINRPC_T_DOUBLE: 
+		case BINRPC_T_DOUBLE:
 			ret=binrpc_add_double_type(pkt, avp->u.fval, avp->type);
 			break;
 		default:
diff --git a/src/modules/ctl/binrpc_run.c b/src/modules/ctl/binrpc_run.c
index 76893eb..e90e1bb 100644
--- a/src/modules/ctl/binrpc_run.c
+++ b/src/modules/ctl/binrpc_run.c
@@ -1070,8 +1070,9 @@ static int rpc_struct_add(struct rpc_struct_l* s, char* fmt, ...)
 			case 's': /* asciiz */
 				avp.type=BINRPC_T_STR;
 				avp.u.strval.s=va_arg(ap, char*);
-				if (avp.u.strval.s)
-					avp.u.strval.len=strlen(avp.u.strval.s);
+				if (avp.u.strval.s==0) /* fix null strings */
+					avp.u.strval.s="<null string>";
+				avp.u.strval.len=strlen(avp.u.strval.s);
 				break;
 			case 'S': /* str */
 				avp.type=BINRPC_T_STR;
@@ -1098,13 +1099,13 @@ static int rpc_struct_add(struct rpc_struct_l* s, char* fmt, ...)
 				}
 				clist_append(&s->substructs, rs, next, prev);
 				*(va_arg(ap, void**))=rs;
-				goto end;
+				break;
 			case 'f':
 				avp.type=BINRPC_T_DOUBLE;
 				avp.u.fval=va_arg(ap, double);
 				break;
 			default:
-				LM_ERR("formatting char \'%c\'" " not supported\n", *fmt);
+				LM_ERR("formatting char \'%c\' not supported\n", *fmt);
 				goto error;
 		}
 		err=binrpc_addavp(&s->pkt, &avp);




More information about the sr-dev mailing list