Change in openvpn[master]: mudp: fix unaligned 32-bit read when parsing peer ID
A message that is not in the archive (sent off-list or not yet received): gerrit.1762271909000.Id0bb4c45d373437ab8dbaff7a311745f9b538cbf@...2715...
Attention is currently required from: flichtenheld, plaisthos.
Hello plaisthos, flichtenheld,
I'd like you to do a code review.
Please visit
http://gerrit.openvpn.net/c/openvpn/+/1348?usp=email
to review the following change.
Change subject: mudp: fix unaligned 32-bit read when parsing peer ID
......................................................................
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.
This patch replaces the unsafe cast with a safe
memcpy-based read.
---
M src/openvpn/mudp.c
1 file changed, 3 insertions(+), 1 deletion(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/48/1348/1
src/openvpn/mudp.c +3 -1
@@ -209,7 +209,9 @@/* make sure buffer has enough length to read opcode (1 byte) and peer-id (3 bytes) */ if (v2) { -uint32_t peer_id =ntohl (*(uint32_t *)ptr) &0xFFFFFF ; +uint32_t tmp; +memcpy (&tmp, ptr,sizeof (tmp)); +uint32_t peer_id =ntohl (tmp) &0xFFFFFF ; peer_id_disabled = (peer_id ==MAX_PEER_ID );if (!peer_id_disabled && (peer_id < m->max_clients) && (m->instances[peer_id]))
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1348?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id0bb4c45d373437ab8dbaff7a311745f9b538cbf
Gerrit-Change-Number: 1348
Gerrit-PatchSet: 1
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Attention is currently required from: its_Giaan, plaisthos.
flichtenheld has posted comments on this change by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/1348?usp=email )
Change subject: mudp: fix unaligned 32-bit read when parsing peer ID
......................................................................
Patch Set 1: Code-Review+2
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1348?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id0bb4c45d373437ab8dbaff7a311745f9b538cbf
Gerrit-Change-Number: 1348
Gerrit-PatchSet: 1
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Comment-Date: Thu, 06 Nov 2025 13:19:53 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
PATCH 1/1 mudp: fix unaligned 32-bit read when parsing peer ID
In reply to a message not in the archiveFrom: Gianmarco De Gregori <[email protected]...>
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.
This patch replaces the unsafe cast with a safe
memcpy-based read.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1348
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1348
This mail reflects revision 1 of this Change.
Acked-by according to Gerrit (reflected above):
Frank Lichtenheld <[email protected]...>
src/openvpn/mudp.c +3 -1
@@ -209,7 +209,9 @@/* make sure buffer has enough length to read opcode (1 byte) and peer-id (3 bytes) */ if (v2) { -uint32_t peer_id =ntohl (*(uint32_t *)ptr) &0xFFFFFF ; +uint32_t tmp; +memcpy (&tmp, ptr,sizeof (tmp)); +uint32_t peer_id =ntohl (tmp) &0xFFFFFF ; peer_id_disabled = (peer_id ==MAX_PEER_ID );if (!peer_id_disabled && (peer_id < m->max_clients) && (m->instances[peer_id]))
Attention is currently required from: its_Giaan, plaisthos.
flichtenheld has posted comments on this change by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/1348?usp=email )
Change subject: mudp: fix unaligned 32-bit read when parsing peer ID
......................................................................
Patch Set 1:
(1 comment)
File src/openvpn/mudp.c:
http://gerrit.openvpn.net/c/openvpn/+/1348/comment/b1c152bd_e837d78c?usp=email :
PS1, Line 213: memcpy(&tmp, ptr, sizeof(tmp));
This reimplements the same logic as buf_read_u32() except that it doesn't advance the buffer. Would it be possible to use that function instead?
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1348?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id0bb4c45d373437ab8dbaff7a311745f9b538cbf
Gerrit-Change-Number: 1348
Gerrit-PatchSet: 1
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Comment-Date: Fri, 14 Nov 2025 16:07:51 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Attention is currently required from: its_Giaan, plaisthos.
cron2 has posted comments on this change by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/1348?usp=email )
Change subject: mudp: fix unaligned 32-bit read when parsing peer ID
......................................................................
Patch Set 1:
(1 comment)
File src/openvpn/mudp.c:
http://gerrit.openvpn.net/c/openvpn/+/1348/comment/3f419bdf_37dbf5a2?usp=email :
PS1, Line 213: memcpy(&tmp, ptr, sizeof(tmp));
Quoted 1 line
This reimplements the same logic as
buf_read_u32()except that it doesn't advance the buffer. […]
I am thinking of something more straightforward...
``` /* peer_id is a 24 byte integer in network byte order */ peer_id = (ptr[1]<<16) + (ptr[2]<<8) + ptr[3] ```
(or the other way round, didn't do the byte order calculations yet)...
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1348?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id0bb4c45d373437ab8dbaff7a311745f9b538cbf
Gerrit-Change-Number: 1348
Gerrit-PatchSet: 1
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Comment-Date: Fri, 14 Nov 2025 18:39:24 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Attention is currently required from: flichtenheld, its_Giaan, plaisthos.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/1348?usp=email
to look at the new patch set (#2).
The following approvals got outdated and were removed:
Code-Review+2 by flichtenheld
The change is no longer submittable: Code-Review and checks~ChecksSubmitRule are unsatisfied now.
Change subject: mudp: fix unaligned 32-bit read when parsing peer ID
......................................................................
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 read the bytes individually and combine them manually.
---
M src/openvpn/mudp.c
1 file changed, 1 insertion(+), 1 deletion(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/48/1348/2
src/openvpn/mudp.c +1 -1
@@ -209,7 +209,7 @@/* make sure buffer has enough length to read opcode (1 byte) and peer-id (3 bytes) */ if (v2) { -uint32_t peer_id =ntohl (*(uint32_t *)ptr) &0xFFFFFF ; +uint32_t peer_id = ((uint32_t )ptr[1 ] <<16 ) | ((uint32_t )ptr[2 ] <<8 ) | ((uint32_t )ptr[3 ]); peer_id_disabled = (peer_id ==MAX_PEER_ID );if (!peer_id_disabled && (peer_id < m->max_clients) && (m->instances[peer_id]))
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1348?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id0bb4c45d373437ab8dbaff7a311745f9b538cbf
Gerrit-Change-Number: 1348
Gerrit-PatchSet: 2
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Attention is currently required from: cron2, flichtenheld, plaisthos.
its_Giaan has posted comments on this change by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/1348?usp=email )
Change subject: mudp: fix unaligned 32-bit read when parsing peer ID
......................................................................
Patch Set 2:
(1 comment)
File src/openvpn/mudp.c:
http://gerrit.openvpn.net/c/openvpn/+/1348/comment/6833f3d3_0f5de10b?usp=email :
PS1, Line 213: memcpy(&tmp, ptr, sizeof(tmp));
Quoted 1 line
I am thinking of something more straightforward... […]
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1348?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id0bb4c45d373437ab8dbaff7a311745f9b538cbf
Gerrit-Change-Number: 1348
Gerrit-PatchSet: 2
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Mon, 01 Dec 2025 16:03:31 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Comment-In-Reply-To: flichtenheld <[email protected]...>
Attention is currently required from: cron2, its_Giaan, plaisthos.
flichtenheld has posted comments on this change by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/1348?usp=email )
Change subject: mudp: fix unaligned 32-bit read when parsing peer ID
......................................................................
Patch Set 2:
(1 comment)
Commit Message:
http://gerrit.openvpn.net/c/openvpn/+/1348/comment/937807d7_bfbf6f4f?usp=email :
PS2, Line 15: Fix this by read the bytes individually and combine
Either "Fix this by reading the bytes individually and combining them manually." Or "To fix this read the bytes individually and combine them manually."
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1348?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id0bb4c45d373437ab8dbaff7a311745f9b538cbf
Gerrit-Change-Number: 1348
Gerrit-PatchSet: 2
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Comment-Date: Mon, 01 Dec 2025 16:20:52 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Attention is currently required from: cron2, its_Giaan, plaisthos.
Hello flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/1348?usp=email
to look at the new patch set (#3).
Change subject: mudp: fix unaligned 32-bit read when parsing peer ID
......................................................................
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.
---
M src/openvpn/mudp.c
1 file changed, 1 insertion(+), 1 deletion(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/48/1348/3
src/openvpn/mudp.c +1 -1
@@ -209,7 +209,7 @@/* make sure buffer has enough length to read opcode (1 byte) and peer-id (3 bytes) */ if (v2) { -uint32_t peer_id =ntohl (*(uint32_t *)ptr) &0xFFFFFF ; +uint32_t peer_id = ((uint32_t )ptr[1 ] <<16 ) | ((uint32_t )ptr[2 ] <<8 ) | ((uint32_t )ptr[3 ]); peer_id_disabled = (peer_id ==MAX_PEER_ID );if (!peer_id_disabled && (peer_id < m->max_clients) && (m->instances[peer_id]))
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1348?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id0bb4c45d373437ab8dbaff7a311745f9b538cbf
Gerrit-Change-Number: 1348
Gerrit-PatchSet: 3
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Attention is currently required from: cron2, flichtenheld, plaisthos.
its_Giaan has posted comments on this change by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/1348?usp=email )
Change subject: mudp: fix unaligned 32-bit read when parsing peer ID
......................................................................
Patch Set 3:
(1 comment)
Commit Message:
http://gerrit.openvpn.net/c/openvpn/+/1348/comment/c8e93574_8ee11a7d?usp=email :
PS2, Line 15: Fix this by read the bytes individually and combine
Quoted 1 line
Either "Fix this by reading the bytes individually and combining them manually. […]
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1348?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id0bb4c45d373437ab8dbaff7a311745f9b538cbf
Gerrit-Change-Number: 1348
Gerrit-PatchSet: 3
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: cron2 <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Mon, 01 Dec 2025 21:17:14 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>
Attention is currently required from: flichtenheld, its_Giaan, plaisthos.
cron2 has posted comments on this change by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/1348?usp=email )
Change subject: mudp: fix unaligned 32-bit read when parsing peer ID
......................................................................
Patch Set 3: Code-Review+2
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1348?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id0bb4c45d373437ab8dbaff7a311745f9b538cbf
Gerrit-Change-Number: 1348
Gerrit-PatchSet: 3
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Wed, 10 Dec 2025 10:48:24 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
PATCH v3 1/1 mudp: fix unaligned 32-bit read when parsing peer ID
In reply to a message not in the archiveFrom: Gianmarco De Gregori <[email protected]...>
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.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1348
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1348
This mail reflects revision 3 of this Change.
Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>
src/openvpn/mudp.c +1 -1
@@ -209,7 +209,7 @@/* make sure buffer has enough length to read opcode (1 byte) and peer-id (3 bytes) */ if (v2) { -uint32_t peer_id =ntohl (*(uint32_t *)ptr) &0xFFFFFF ; +uint32_t peer_id = ((uint32_t )ptr[1 ] <<16 ) | ((uint32_t )ptr[2 ] <<8 ) | ((uint32_t )ptr[3 ]); peer_id_disabled = (peer_id ==MAX_PEER_ID );if (!peer_id_disabled && (peer_id < m->max_clients) && (m->instances[peer_id]))
[Openvpn-devel] [PATCH applied] Re: mudp: fix unaligned 32-bit read when parsing peer ID
Not sure the new code is less or more ugly than the old code... but it's less ugly than v1 of the patch :-)
I have lightly tested this, and instrumented my t_server test bed to add an ASSERT(old_peer_id == peer_id) check. I do not have peer IDs > 255, and the p2p mode (which uses random-high peer IDs) does not use *this* code path, so "exposure to higher peer-id" has not been tested.
That said, the byte order handling is correct for peer-ids 1 and 2, and stare-at-code suggests it should work fine for up to 24 bits too :-)
*That* said, I'm not sure if this is really a relevant "finding" - yes, it could end up doing unaligned 32bit-reads, but on Intel, this is "just slow" - which byte accesses are, too. The only platform I'm aware that will trap-and-die is SPARC32, and even that should be fine with the code that has been in there for a loooong time... but anyway. I don't think this makes a huge difference either way.
Your patch has been applied to the master branch.
commit 8bf8bead6d7cc3c743fdf2b915fbb2f3f24e7005
Author: Gianmarco De Gregori Date: Wed Dec 10 11:48:33 2025 +0100
mudp: fix unaligned 32-bit read when parsing peer ID
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]...>--
kind regards,
Gert Doering
cron2 has uploaded a new patch set (#4) to the change originally created by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/1348?usp=email )
The following approvals got outdated and were removed:
Code-Review+2 by cron2
Change subject: mudp: fix unaligned 32-bit read when parsing peer ID
......................................................................
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.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1348
Message-Id: <[email protected]...>
---
M src/openvpn/mudp.c
1 file changed, 1 insertion(+), 1 deletion(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/48/1348/4
src/openvpn/mudp.c +1 -1
@@ -209,7 +209,7 @@/* make sure buffer has enough length to read opcode (1 byte) and peer-id (3 bytes) */ if (v2) { -uint32_t peer_id =ntohl (*(uint32_t *)ptr) &0xFFFFFF ; +uint32_t peer_id = ((uint32_t )ptr[1 ] <<16 ) | ((uint32_t )ptr[2 ] <<8 ) | ((uint32_t )ptr[3 ]); peer_id_disabled = (peer_id ==MAX_PEER_ID );if (!peer_id_disabled && (peer_id < m->max_clients) && (m->instances[peer_id]))
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1348?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id0bb4c45d373437ab8dbaff7a311745f9b538cbf
Gerrit-Change-Number: 1348
Gerrit-PatchSet: 4
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1348?usp=email )
Change subject: mudp: fix unaligned 32-bit read when parsing peer ID
......................................................................
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.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1348
Message-Id: <[email protected]...>
---
M src/openvpn/mudp.c
1 file changed, 1 insertion(+), 1 deletion(-)
src/openvpn/mudp.c +1 -1
@@ -209,7 +209,7 @@/* make sure buffer has enough length to read opcode (1 byte) and peer-id (3 bytes) */ if (v2) { -uint32_t peer_id =ntohl (*(uint32_t *)ptr) &0xFFFFFF ; +uint32_t peer_id = ((uint32_t )ptr[1 ] <<16 ) | ((uint32_t )ptr[2 ] <<8 ) | ((uint32_t )ptr[3 ]); peer_id_disabled = (peer_id ==MAX_PEER_ID );if (!peer_id_disabled && (peer_id < m->max_clients) && (m->instances[peer_id]))
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1348?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id0bb4c45d373437ab8dbaff7a311745f9b538cbf
Gerrit-Change-Number: 1348
Gerrit-PatchSet: 4
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>