From 54499f8850fd5b3a25639dc06d5618ae98ac1537 Mon Sep 17 00:00:00 2001 From: Maria Matejka Date: Wed, 27 Nov 2024 12:01:58 +0100 Subject: [PATCH 1/2] String tests: fixed too strict strcmp checks The strcmp function is not guaranteed to return -1 or +1 but any negative or positive value if the input strings are different. Fixed the false assumption which triggered a build bug on emulated arm64. --- lib/printf_test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/printf_test.c b/lib/printf_test.c index 88ecf05e..996f34ae 100644 --- a/lib/printf_test.c +++ b/lib/printf_test.c @@ -108,8 +108,8 @@ static int t_bstrcmp(void) { bt_assert(bstrcmp("aa", "aa") == 0); - bt_assert(bstrcmp("aa", "bb") == -1); - bt_assert(bstrcmp("bb", "aa") == 1); + bt_assert(bstrcmp("aa", "bb") < 0); + bt_assert(bstrcmp("bb", "aa") > 0); bt_assert(bstrcmp(NULL, NULL) == 0); bt_assert(bstrcmp(NULL, "bb") == -1); bt_assert(bstrcmp("bb", NULL) == 1); From 3ca6e03db774f0a2d462faf20646e4a341664c8d Mon Sep 17 00:00:00 2001 From: Maria Matejka Date: Thu, 28 Nov 2024 14:10:40 +0100 Subject: [PATCH 2/2] RPKI: refactored pdu to host byte order conversion We shouldn't convert bytes 2 and 3 of the PDU blindly, there are several cases where these are used by bytes. Instead, the conversion is done only where needed. This fixes misinterpretation bug of ASPA PDU flags on little endian architectures. --- proto/rpki/packets.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/proto/rpki/packets.c b/proto/rpki/packets.c index 6d2ec9d1..f23cf467 100644 --- a/proto/rpki/packets.c +++ b/proto/rpki/packets.c @@ -306,26 +306,22 @@ rpki_pdu_to_network_byte_order(struct pdu_header *pdu) static void rpki_pdu_to_host_byte_order(struct pdu_header *pdu) { - /* The Router Key PDU has two one-byte fields instead of one two-bytes field. */ - if (pdu->type != ROUTER_KEY) - pdu->reserved = ntohs(pdu->reserved); - pdu->len = ntohl(pdu->len); switch (pdu->type) { case SERIAL_NOTIFY: { - /* Note that a session_id is converted using converting header->reserved */ struct pdu_serial_notify *sn_pdu = (void *) pdu; + sn_pdu->session_id = ntohs(sn_pdu->session_id); sn_pdu->serial_num = ntohl(sn_pdu->serial_num); break; } case END_OF_DATA: { - /* Note that a session_id is converted using converting header->reserved */ struct pdu_end_of_data_v0 *eod0 = (void *) pdu; + eod0->session_id = ntohs(eod0->session_id); eod0->serial_num = ntohl(eod0->serial_num); /* Same either for version 1 */ if (pdu->ver > RPKI_VERSION_0) @@ -356,8 +352,8 @@ rpki_pdu_to_host_byte_order(struct pdu_header *pdu) case ERROR: { - /* Note that a error_code is converted using converting header->reserved */ struct pdu_error *err = (void *) pdu; + err->error_code = ntohs(err->error_code); err->len_enc_pdu = ntohl(err->len_enc_pdu); u32 *err_text_len = (u32 *)(err->rest + err->len_enc_pdu); *err_text_len = htonl(*err_text_len); @@ -388,8 +384,14 @@ rpki_pdu_to_host_byte_order(struct pdu_header *pdu) * We don't care here. */ case CACHE_RESPONSE: + { + struct pdu_cache_response *cr = (void *) pdu; + cr->session_id = ntohs(cr->session_id); + break; + } + case CACHE_RESET: - /* Converted with pdu->reserved */ + /* Nothing to convert */ break; } }