diff --git a/src/modules/ctl/binrpc_run.c b/src/modules/ctl/binrpc_run.c index 1ce9800553c..8c786a680ad 100644 --- a/src/modules/ctl/binrpc_run.c +++ b/src/modules/ctl/binrpc_run.c @@ -961,10 +961,11 @@ static int rpc_add(struct binrpc_ctx* ctx, char* fmt, ...) { va_list ap; int err; - char* s; - str* st; + str st; + str* sp; struct rpc_struct_l* rs; - + str null_value = str_init(""); + va_start(ap, fmt); for (;*fmt; fmt++){ switch(*fmt){ @@ -976,15 +977,24 @@ static int rpc_add(struct binrpc_ctx* ctx, char* fmt, ...) if (err<0) goto error_add; break; case 's': /* asciiz */ - s=va_arg(ap, char*); - if (s==0) /* fix null strings */ - s=""; - err=binrpc_addstr(&ctx->out.pkt, s, strlen(s)); + st.s=va_arg(ap, char*); + if (st.s==0) { + /* fix null strings */ + st=null_value; + } else { + st.len=strlen(st.s); + } + err=binrpc_addstr(&ctx->out.pkt, st.s, st.len); if (err<0) goto error_add; break; case 'S': /* str */ - st=va_arg(ap, str*); - err=binrpc_addstr(&ctx->out.pkt, st->s, st->len); + sp=va_arg(ap, str*); + if(sp!=NULL && sp->s!=NULL) { + st=*sp; + } else { + st=null_value; + } + err=binrpc_addstr(&ctx->out.pkt, st.s, st.len); if (err<0) goto error_add; break; case '{': @@ -999,11 +1009,11 @@ static int rpc_add(struct binrpc_ctx* ctx, char* fmt, ...) clist_append(&ctx->out.structs, rs, next, prev); *(va_arg(ap, void**))=rs; break; - case 'f': + case 'f': err=binrpc_adddouble(&ctx->out.pkt, va_arg(ap, double)); if (err<0) goto error_add; break; - default: + default: rpc_fault(ctx, 500, "Internal server error: " "invalid formatting character \'%c\'", *fmt); LOG(L_CRIT, "BUG: binrpc: rpc_add: formatting char \'%c\'" @@ -1067,6 +1077,8 @@ static int rpc_struct_add(struct rpc_struct_l* s, char* fmt, ...) int err; struct binrpc_val avp; struct rpc_struct_l* rs; + str *sp; + str null_value = str_init(""); va_start(ap, fmt); for (;*fmt; fmt++){ @@ -1085,13 +1097,21 @@ 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==0) /* fix null strings */ - avp.u.strval.s=""; - avp.u.strval.len=strlen(avp.u.strval.s); + if (avp.u.strval.s==NULL) { + /* fix null strings */ + avp.u.strval=null_value; + } else { + avp.u.strval.len=strlen(avp.u.strval.s); + } break; case 'S': /* str */ avp.type=BINRPC_T_STR; - avp.u.strval=*(va_arg(ap, str*)); + sp = va_arg(ap, str*); + if(sp!=NULL && sp->s!=NULL) { + avp.u.strval=*sp; + } else { + avp.u.strval=null_value; + } break; case '{': case '[': @@ -1144,9 +1164,10 @@ static int rpc_array_add(struct rpc_struct_l* s, char* fmt, ...) { va_list ap; int err; - char* sv; - str* st; + str st; + str *sp; struct rpc_struct_l* rs; + str null_value = str_init(""); va_start(ap, fmt); for (;*fmt; fmt++){ @@ -1159,15 +1180,24 @@ static int rpc_array_add(struct rpc_struct_l* s, char* fmt, ...) if (err<0) goto error_add; break; case 's': /* asciiz */ - sv=va_arg(ap, char*); - if (sv==0) /* fix null strings */ - sv=""; - err=binrpc_addstr(&s->pkt, sv, strlen(sv)); + st.s=va_arg(ap, char*); + if (st.s==0) { + /* fix null strings */ + st=null_value; + } else { + st.len = strlen(st.s); + } + err=binrpc_addstr(&s->pkt, st.s, st.len); if (err<0) goto error_add; break; case 'S': /* str */ - st=va_arg(ap, str*); - err=binrpc_addstr(&s->pkt, st->s, st->len); + sp=va_arg(ap, str*); + if(sp!=NULL && sp->s!=NULL) { + st=*sp; + } else { + st=null_value; + } + err=binrpc_addstr(&s->pkt, st.s, st.len); if (err<0) goto error_add; break; case '{': diff --git a/src/modules/ctl/fifo_server.c b/src/modules/ctl/fifo_server.c index e057148059a..b40b079a1d5 100644 --- a/src/modules/ctl/fifo_server.c +++ b/src/modules/ctl/fifo_server.c @@ -1092,6 +1092,7 @@ static int print_value(rpc_ctx_t* ctx, char fmt, va_list* ap) str str_val; str* sp; char buf[256]; + str null_value = str_init(""); switch(fmt) { case 'd': @@ -1104,7 +1105,7 @@ static int print_value(rpc_ctx_t* ctx, char fmt, va_list* ap) goto err; } break; - + case 'f': str_val.s = buf; str_val.len = snprintf(buf, 256, "%f", va_arg(*ap, double)); @@ -1120,39 +1121,48 @@ static int print_value(rpc_ctx_t* ctx, char fmt, va_list* ap) goto err; } break; - + case 'b': str_val.len = 1; str_val.s = ((va_arg(*ap, int) == 0) ? "0" : "1"); l = new_chunk(&str_val); if (!l) { - rpc_fault(ctx, 500, "Internal Server Error, line %d", + rpc_fault(ctx, 500, "Internal Server Error, line %d", ctx->line_no); goto err; } break; - + case 's': str_val.s = va_arg(*ap, char*); - str_val.len = strlen(str_val.s); + if(str_val.s!=NULL) { + str_val.len = strlen(str_val.s); + } else { + str_val = null_value; + } l = new_chunk_escape(&str_val, 0); if (!l) { - rpc_fault(ctx, 500, "Internal Server Error, line %d", + rpc_fault(ctx, 500, "Internal Server Error, line %d", ctx->line_no); goto err; } break; - + case 'S': sp = va_arg(*ap, str*); - l = new_chunk_escape(sp, 0); + if(sp!=NULL && sp->s!=NULL) { + str_val = *sp; + } else { + str_val = null_value; + } + l = new_chunk_escape(&str_val, 0); if (!l) { - rpc_fault(ctx, 500, "Internal Server Error, line %d", + rpc_fault(ctx, 500, "Internal Server Error, line %d", ctx->line_no); goto err; } break; - + default: rpc_fault(ctx, 500, "Bug In SER (Invalid formatting character %c)", fmt); ERR("Invalid formatting character\n"); @@ -1368,7 +1378,7 @@ static int rpc_scan(rpc_ctx_t* ctx, char* fmt, ...) case 'd': /* Integer */ if (!line.len) { if(nofault==0) - rpc_fault(ctx, 400, "Invalid parameter value on line %d", + rpc_fault(ctx, 400, "Invalid parameter value on line %d", ctx->line_no); goto error; } @@ -1379,14 +1389,14 @@ static int rpc_scan(rpc_ctx_t* ctx, char* fmt, ...) case 'f': /* double */ if (!line.len) { if(nofault==0) - rpc_fault(ctx, 400, "Invalid parameter value on line %d", + rpc_fault(ctx, 400, "Invalid parameter value on line %d", ctx->line_no); goto error; } double_ptr = va_arg(ap, double*); *double_ptr = strtod(line.s, 0); break; - + case 's': /* zero terminated string */ case 'S': /* str structure */ l = new_chunk_unescape(&line); @@ -1444,6 +1454,7 @@ static int rpc_struct_add(struct text_chunk* s, char* fmt, ...) va_list ap; struct text_chunk* m, *c; rpc_ctx_t* ctx; + str null_value = str_init(""); ctx=(rpc_ctx_t*)s->ctx; va_start(ap, fmt); @@ -1457,7 +1468,7 @@ static int rpc_struct_add(struct text_chunk* s, char* fmt, ...) goto err; } m->flags |= CHUNK_MEMBER_NAME; - + if(*fmt=='{' || *fmt=='[') { void_ptr = va_arg(ap, void**); m->ctx=ctx; @@ -1490,13 +1501,22 @@ static int rpc_struct_add(struct text_chunk* s, char* fmt, ...) case 's': st.s = va_arg(ap, char*); - st.len = strlen(st.s); + if(st.s==NULL) { + st = null_value; + } else { + st.len = strlen(st.s); + } c = new_chunk_escape(&st, 1); break; case 'S': sp = va_arg(ap, str*); - c = new_chunk_escape(sp, 1); + if(sp!=NULL && sp->s!=NULL) { + st = *sp; + } else { + st = null_value; + } + c = new_chunk_escape(&st, 1); break; default: @@ -1576,7 +1596,7 @@ static int rpc_struct_scan(struct rpc_struct* s, char* fmt, ...) va_end(ap); return read; } - + switch(*fmt) { case 'b': /* Bool */ case 't': /* Date and time */ @@ -1599,7 +1619,7 @@ static int rpc_struct_scan(struct rpc_struct* s, char* fmt, ...) /* String in text_chunk is always zero terminated */ *double_ptr = strtod(val->s.s, 0); break; - + case 's': /* zero terminated string */ char_ptr = va_arg(ap, char**); /* String in text_chunk is always zero terminated */ @@ -1608,7 +1628,6 @@ static int rpc_struct_scan(struct rpc_struct* s, char* fmt, ...) case 'S': /* str structure */ str_ptr = va_arg(ap, str*); - str_ptr->len = strlen(str_ptr->s); *str_ptr = val->s; break; default: