test/fuzz: Fix use of htons vs. ntohs

Although ntohs and htons perform equivalent operations (a byte swap on
little-endian platforms), their semantic roles (as implied by the names)
are different.

In fuzz_common.c, we get integers from simulated network packages, and
convert them for host CPU use, so ntohs is the right variant to use.
This commit is contained in:
Jonathan Neuschäfer 2023-04-07 14:26:32 +02:00 committed by Simon Goldschmidt
parent 5514d8eb63
commit c2f9244137

View File

@ -232,7 +232,7 @@ static void input_pkts(enum lwip_fuzz_type type, struct netif *netif, const u8_t
#ifdef LWIP_FUZZ_SYS_NOW
/* Extract external delay time from fuzz pool */
memcpy(&external_delay, remfuzz_ptr, sizeof(u32_t));
external_delay = htonl(external_delay);
external_delay = ntohl(external_delay);
#endif
remfuzz_ptr += sizeof(u32_t);
remfuzz_len -= sizeof(u32_t);
@ -240,7 +240,7 @@ static void input_pkts(enum lwip_fuzz_type type, struct netif *netif, const u8_t
memcpy(&frame_len, remfuzz_ptr, sizeof(u16_t));
remfuzz_ptr += sizeof(u16_t);
remfuzz_len -= sizeof(u16_t);
frame_len = htons(frame_len) & 0x7FF;
frame_len = ntohs(frame_len) & 0x7FF;
frame_len = LWIP_MIN(frame_len, max_packet_size);
if (frame_len > remfuzz_len) {
frame_len = (u16_t)remfuzz_len;
@ -287,7 +287,7 @@ tcp_app_fuzz_input(struct altcp_pcb *pcb)
memcpy(&data_len, remfuzz_ptr, sizeof(u16_t));
remfuzz_ptr += sizeof(u16_t);
remfuzz_len -= sizeof(u16_t);
data_len = htons(data_len);
data_len = ntohs(data_len);
data_len = LWIP_MIN(data_len, max_data_size);
if (data_len > remfuzz_len) {
data_len = (u16_t)remfuzz_len;
@ -490,7 +490,7 @@ udp_app_fuzz_input(struct udp_pcb *pcb, const ip_addr_t *addr, u16_t port)
memcpy(&data_len, remfuzz_ptr, sizeof(u16_t));
remfuzz_ptr += sizeof(u16_t);
remfuzz_len -= sizeof(u16_t);
data_len = htons(data_len);
data_len = ntohs(data_len);
data_len = LWIP_MIN(data_len, max_data_size);
if (data_len > remfuzz_len) {
data_len = (u16_t)remfuzz_len;