CLEANUP: peers: factor error handling in peer_treat_definedmsg()

This is a trivial code refactoring of similar parsing error code
under a single label.
This commit is contained in:
Willy Tarreau 2019-01-29 11:11:23 +01:00
parent 1e82a14c34
commit 6f731f33ac

View File

@ -1396,25 +1396,16 @@ static inline int peer_treat_definemsg(struct appctx *appctx, struct peer *p,
uint64_t table_data; uint64_t table_data;
table_id = intdecode(msg_cur, msg_end); table_id = intdecode(msg_cur, msg_end);
if (!*msg_cur) { if (!*msg_cur)
/* malformed message */ goto malformed_exit;
appctx->st0 = PEER_SESS_ST_ERRPROTO;
return 0;
}
table_id_len = intdecode(msg_cur, msg_end); table_id_len = intdecode(msg_cur, msg_end);
if (!*msg_cur) { if (!*msg_cur)
/* malformed message */ goto malformed_exit;
appctx->st0 = PEER_SESS_ST_ERRPROTO;
return 0;
}
p->remote_table = NULL; p->remote_table = NULL;
if (!table_id_len || (*msg_cur + table_id_len) >= msg_end) { if (!table_id_len || (*msg_cur + table_id_len) >= msg_end)
/* malformed message */ goto malformed_exit;
appctx->st0 = PEER_SESS_ST_ERRPROTO;
return 0;
}
for (st = p->tables; st; st = st->next) { for (st = p->tables; st; st = st->next) {
/* Reset IDs */ /* Reset IDs */
@ -1430,32 +1421,20 @@ static inline int peer_treat_definemsg(struct appctx *appctx, struct peer *p,
goto ignore_msg; goto ignore_msg;
*msg_cur += table_id_len; *msg_cur += table_id_len;
if (*msg_cur >= msg_end) { if (*msg_cur >= msg_end)
/* malformed message */ goto malformed_exit;
appctx->st0 = PEER_SESS_ST_ERRPROTO;
return 0;
}
table_type = intdecode(msg_cur, msg_end); table_type = intdecode(msg_cur, msg_end);
if (!*msg_cur) { if (!*msg_cur)
/* malformed message */ goto malformed_exit;
appctx->st0 = PEER_SESS_ST_ERRPROTO;
return 0;
}
table_keylen = intdecode(msg_cur, msg_end); table_keylen = intdecode(msg_cur, msg_end);
if (!*msg_cur) { if (!*msg_cur)
/* malformed message */ goto malformed_exit;
appctx->st0 = PEER_SESS_ST_ERRPROTO;
return 0;
}
table_data = intdecode(msg_cur, msg_end); table_data = intdecode(msg_cur, msg_end);
if (!*msg_cur) { if (!*msg_cur)
/* malformed message */ goto malformed_exit;
appctx->st0 = PEER_SESS_ST_ERRPROTO;
return 0;
}
if (p->remote_table->table->type != table_type if (p->remote_table->table->type != table_type
|| p->remote_table->table->key_size != table_keylen) { || p->remote_table->table->key_size != table_keylen) {
@ -1470,6 +1449,11 @@ static inline int peer_treat_definemsg(struct appctx *appctx, struct peer *p,
ignore_msg: ignore_msg:
co_skip(si_oc(si), totl); co_skip(si_oc(si), totl);
return 0; return 0;
malformed_exit:
/* malformed message */
appctx->st0 = PEER_SESS_ST_ERRPROTO;
return 0;
} }
/* /*