Skip to content

Commit 8bf8bea

Browse files
itsGiaancron2
authored andcommitted
mudp: fix unaligned 32-bit read when parsing peer ID
The code previously read a 32-bit value from a uint8_t buffer using a direct cast and dereference. This can cause unaligned memory access and undefined behavior on architectures that do not support unaligned reads, potentially leading to a one-packet crash. Fix this by reading the bytes individually and combining them manually. Reported-By: Joshua Rogers <[email protected]> Found-By: ZeroPath (https://zeropath.com) Change-Id: Id0bb4c45d373437ab8dbaff7a311745f9b538cbf Signed-off-by: Gianmarco De Gregori <[email protected]> Acked-by: Gert Doering <[email protected]> Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1348 Message-Id: <[email protected]> Signed-off-by: Gert Doering <[email protected]>
1 parent f7afbc5 commit 8bf8bea

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/openvpn/mudp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ multi_get_create_instance_udp(struct multi_context *m, bool *floated, struct lin
209209
/* make sure buffer has enough length to read opcode (1 byte) and peer-id (3 bytes) */
210210
if (v2)
211211
{
212-
uint32_t peer_id = ntohl(*(uint32_t *)ptr) & 0xFFFFFF;
212+
uint32_t peer_id = ((uint32_t)ptr[1] << 16) | ((uint32_t)ptr[2] << 8) | ((uint32_t)ptr[3]);
213213
peer_id_disabled = (peer_id == MAX_PEER_ID);
214214

215215
if (!peer_id_disabled && (peer_id < m->max_clients) && (m->instances[peer_id]))

0 commit comments

Comments
 (0)