brei: change the various errors to PROTOCOL

This commit is contained in:
Peter Hutterer 2023-02-21 09:34:37 +10:00
parent cc7a8cb95e
commit a6565fd86b

View file

@ -168,7 +168,7 @@ brei_demarshal(struct brei_context *brei, struct iobuf *buf, const char *signatu
{
size_t nargs = strlen(signature);
if (nargs > 256) {
return brei_result_new(BREI_CONNECTION_DISCONNECT_REASON_ERROR,
return brei_result_new(BREI_CONNECTION_DISCONNECT_REASON_PROTOCOL,
"Too many arguments in signature (%zu)", nargs);
}
@ -202,7 +202,7 @@ brei_demarshal(struct brei_context *brei, struct iobuf *buf, const char *signatu
uint32_t slen32 = bytes_to_int32(slen);
if (end - p < slen32) {
return brei_result_new(BREI_CONNECTION_DISCONNECT_REASON_ERROR,
return brei_result_new(BREI_CONNECTION_DISCONNECT_REASON_PROTOCOL,
"Invalid string length %zu, only %li bytes remaining", slen, (end - p) * 4);
}
@ -210,7 +210,7 @@ brei_demarshal(struct brei_context *brei, struct iobuf *buf, const char *signatu
/* strings must be null-terminated */
if (slen && str[slen - 1] != '\0') {
return brei_result_new(BREI_CONNECTION_DISCONNECT_REASON_ERROR,
return brei_result_new(BREI_CONNECTION_DISCONNECT_REASON_PROTOCOL,
"Message string not zero-terminated");
}
@ -219,7 +219,7 @@ brei_demarshal(struct brei_context *brei, struct iobuf *buf, const char *signatu
break;
}
default:
return brei_result_new(BREI_CONNECTION_DISCONNECT_REASON_ERROR,
return brei_result_new(BREI_CONNECTION_DISCONNECT_REASON_PROTOCOL,
"Invalid signature '%c'", *s);
}
arg++;
@ -277,7 +277,7 @@ brei_marshal(struct brei_context *brei, struct iobuf *buf, const char *signature
break;
}
default:
return brei_result_new(BREI_CONNECTION_DISCONNECT_REASON_ERROR,
return brei_result_new(BREI_CONNECTION_DISCONNECT_REASON_PROTOCOL,
"Invalid signature '%c'", *s);
}
s++;
@ -470,7 +470,7 @@ MUNIT_TEST(test_brei_marshal_bad_sig)
_unref_(brei_result) *result = brei_demarshal(brei, buf, "nxoiusf", &nargs, &args);
munit_assert_ptr_not_null(result);
munit_assert_int(brei_result_get_reason(result), ==,
BREI_CONNECTION_DISCONNECT_REASON_ERROR);
BREI_CONNECTION_DISCONNECT_REASON_PROTOCOL);
munit_assert_int(nargs, ==, 789); /* nargs must not be touched on error */
return MUNIT_OK;