Browse code

ctl: proper handling of optional param specifier (*) in rpc scan

(cherry picked from commit a9972863681059c647af4bafd0d9a20f7648c801)
(cherry picked from commit 427145b9cdadf01a18b3f38ffdb14094154a647a)
(cherry picked from commit 62b2c0e8a2670c93be3d6dbbe60a818bc0c6fc35)

Daniel-Constantin Mierla authored on 23/01/2018 16:33:39
Showing 1 changed files
... ...
@@ -838,11 +838,11 @@ static int rpc_scan(struct binrpc_ctx* ctx, char* fmt, ...)
838 838
 	/* clear the previously saved error code */
839 839
 	rpc_fault_reset(ctx);
840 840
 
841
-	va_start(ap, fmt);
842 841
 	orig_fmt=fmt;
843 842
 	nofault = 0;
844 843
 	modifiers=0;
845 844
 	autoconv=autoconvert;
845
+	va_start(ap, fmt);
846 846
 	for (;*fmt; fmt++){
847 847
 		switch(*fmt){
848 848
 			case '*': /* start of optional parameters */
... ...
@@ -915,7 +915,7 @@ static int rpc_scan(struct binrpc_ctx* ctx, char* fmt, ...)
915 915
 error_read:
916 916
 	/* Do not immediately send out the error message, the user might retry the scan with
917 917
 	different parameters */
918
-	if(nofault==0 || ((err!=E_BINRPC_MORE_DATA) && (err!=E_BINRPC_EOP)))
918
+	if(nofault==0 || ((err!=E_BINRPC_MORE_DATA) && (err!=E_BINRPC_EOP))) {
919 919
 		rpc_fault_prepare(ctx, 400, "error at parameter %d: expected %s type but"
920 920
 						" %s", ctx->in.record_no, rpc_type_name(v.type),
921 921
 						 binrpc_error(err));
... ...
@@ -924,6 +924,11 @@ error_read:
924 924
 						": %s", ctx->in.record_no, ctx->in.ctx.offset,
925 925
 								v.type, binrpc_error(err));
926 926
 	*/
927
+	}
928
+	if(nofault==1 && (err==E_BINRPC_MORE_DATA || err==E_BINRPC_EOP)) {
929
+		va_end(ap);
930
+		return (int)(fmt-orig_fmt)-modifiers;
931
+	}
927 932
 	goto error_ret;
928 933
 error_not_supported:
929 934
 	rpc_fault(ctx, 500, "internal server error, type %d not supported",