@@ -43,6 +43,7 @@ int commands_parse(iobuf_t *ibuf)
4343{
4444 unsigned char cmd , * data ;
4545 unsigned int off , msg_len , avail ;
46+ int rc = 0 ;
4647 static const unsigned char r2t_min_size [R2TCMD_MAX ] = {
4748 3 , // R2TCMD_CONN
4849 2 , // R2TCMD_CLOSE
@@ -76,27 +77,35 @@ int commands_parse(iobuf_t *ibuf)
7677 off += 4 ;
7778
7879 cmd = data [off ];
79- if (cmd >= R2TCMD_MAX )
80- return error ("invalid command id 0x%02x" , cmd );
80+ unsigned char * msg = data + off ;
81+ off += msg_len ;
82+ if (cmd >= R2TCMD_MAX ) {
83+ rc = error ("invalid command id 0x%02x" , cmd );
84+ break ;
85+ }
8186
82- if (msg_len < (unsigned int )r2t_min_size [cmd ])
83- return error ("command 0x%02x too short 0x%08x < 0x%08x" ,
87+ if (msg_len < (unsigned int )r2t_min_size [cmd ]) {
88+ rc = error ("command 0x%02x too short 0x%08x < 0x%08x" ,
8489 cmd , msg_len , (unsigned int )r2t_min_size [cmd ]);
90+ break ;
91+ }
8592
86- if (!cmd_handlers [cmd ])
87- return error ("command 0x%02x not supported" , cmd );
93+ if (!cmd_handlers [cmd ]) {
94+ rc = error ("command 0x%02x not supported" , cmd );
95+ break ;
96+ }
8897
8998 // call specific command handler
90- if (cmd_handlers [cmd ]((const r2tmsg_t * )( data + off ) , msg_len ))
91- return -1 ;
92-
93- off += msg_len ;
99+ if (cmd_handlers [cmd ]((const r2tmsg_t * )msg , msg_len )) {
100+ rc = -1 ;
101+ break ;
102+ }
94103 }
95104
96105 if (off > 0 )
97106 iobuf_consume (ibuf , off );
98107
99- return 0 ;
108+ return rc ;
100109}
101110
102111// R2TERR_xxx error strings
0 commit comments