From: "flichtenheld (Code Review)" Date: Tue, 12 Sep 2023 10:19:09 +0000 References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: <37155e5f782173d96d1de2117e4545024e3aaafb-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="zSUzM+IOPLY="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Change type of frame.mss_fix to uint16_t List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: openvpn-devel , plaisthos --zSUzM+IOPLY= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: cron2, plaisthos. Hello cron2, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/268?usp=3Demail to review the following change. Change subject: Change type of frame.mss_fix to uint16_t ...................................................................... Change type of frame.mss_fix to uint16_t Since in the end this always ends up as an uint16_t anyway, just make the conversion much earlier. Cleans up the code and removes some -Wconversion warnings. v2: - proper error handling in options.c Change-Id: Id8321dfbb8ad8d79f4bb2a9da61f8cd6b6c6ee26 Signed-off-by: Frank Lichtenheld --- M src/openvpn/mss.c M src/openvpn/mss.h M src/openvpn/mtu.c M src/openvpn/mtu.h M src/openvpn/options.c 5 files changed, 23 insertions(+), 15 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/68/268/3 diff --git a/src/openvpn/mss.c b/src/openvpn/mss.c index dbd3681..d7ee4c2 100644 --- a/src/openvpn/mss.c +++ b/src/openvpn/mss.c @@ -44,7 +44,7 @@ * if yes, hand to mss_fixup_dowork() */ void -mss_fixup_ipv4(struct buffer *buf, int maxmss) +mss_fixup_ipv4(struct buffer *buf, uint16_t maxmss) { const struct openvpn_iphdr *pip; int hlen; @@ -72,7 +72,7 @@ struct openvpn_tcphdr *tc =3D (struct openvpn_tcphdr *) BPTR(&= newbuf); if (tc->flags & OPENVPN_TCPH_SYN_MASK) { - mss_fixup_dowork(&newbuf, (uint16_t) maxmss); + mss_fixup_dowork(&newbuf, maxmss); } } } @@ -84,7 +84,7 @@ * (IPv6 header structure is sufficiently different from IPv4= ...) */ void -mss_fixup_ipv6(struct buffer *buf, int maxmss) +mss_fixup_ipv6(struct buffer *buf, uint16_t maxmss) { const struct openvpn_ipv6hdr *pip6; struct buffer newbuf; @@ -130,7 +130,7 @@ struct openvpn_tcphdr *tc =3D (struct openvpn_tcphdr *) BPTR(&newb= uf); if (tc->flags & OPENVPN_TCPH_SYN_MASK) { - mss_fixup_dowork(&newbuf, (uint16_t) maxmss-20); + mss_fixup_dowork(&newbuf, maxmss-20); } } } @@ -191,13 +191,14 @@ { continue; } - mssval =3D (opt[2]<<8)+opt[3]; + mssval =3D opt[2] << 8; + mssval +=3D opt[3]; if (mssval > maxmss) { - dmsg(D_MSS, "MSS: %d -> %d", (int) mssval, (int) maxms= s); + dmsg(D_MSS, "MSS: %" PRIu16 " -> %" PRIu16, mssval, ma= xmss); accumulate =3D htons(mssval); - opt[2] =3D (maxmss>>8)&0xff; - opt[3] =3D maxmss&0xff; + opt[2] =3D (uint8_t)((maxmss>>8)&0xff); + opt[3] =3D (uint8_t)(maxmss&0xff); accumulate -=3D htons(maxmss); ADJUST_CHECKSUM(accumulate, tc->check); } @@ -291,7 +292,7 @@ { /* we subtract IPv4 and TCP overhead here, mssfix method will add = the * extra 20 for IPv6 */ - frame->mss_fix =3D options->ce.mssfix - (20 + 20); + frame->mss_fix =3D (uint16_t)(options->ce.mssfix - (20 + 20)); return; } @@ -325,7 +326,7 @@ /* This is the target value our payload needs to be smaller */ unsigned int target =3D options->ce.mssfix - overhead; - frame->mss_fix =3D adjust_payload_max_cbc(kt, target) - payload_overhe= ad; + frame->mss_fix =3D (uint16_t)(adjust_payload_max_cbc(kt, target) - pay= load_overhead); } diff --git a/src/openvpn/mss.h b/src/openvpn/mss.h index 1c4704b..b2a68cf 100644 --- a/src/openvpn/mss.h +++ b/src/openvpn/mss.h @@ -29,9 +29,9 @@ #include "mtu.h" #include "ssl_common.h" =20 -void mss_fixup_ipv4(struct buffer *buf, int maxmss); +void mss_fixup_ipv4(struct buffer *buf, uint16_t maxmss); -void mss_fixup_ipv6(struct buffer *buf, int maxmss); +void mss_fixup_ipv6(struct buffer *buf, uint16_t maxmss); void mss_fixup_dowork(struct buffer *buf, uint16_t maxmss); diff --git a/src/openvpn/mtu.c b/src/openvpn/mtu.c index 132f93c..389d140 100644 --- a/src/openvpn/mtu.c +++ b/src/openvpn/mtu.c @@ -210,7 +210,7 @@ buf_printf(&out, "%s ", prefix); } buf_printf(&out, "["); - buf_printf(&out, " mss_fix:%d", frame->mss_fix); + buf_printf(&out, " mss_fix:%" PRIu16, frame->mss_fix); #ifdef ENABLE_FRAGMENT buf_printf(&out, " max_frag:%d", frame->max_fragment_size); #endif diff --git a/src/openvpn/mtu.h b/src/openvpn/mtu.h index b602b86..c64398d 100644 --- a/src/openvpn/mtu.h +++ b/src/openvpn/mtu.h @@ -115,7 +115,7 @@ * decryption/encryption or compression.= */ } buf; - unsigned int mss_fix; /**< The actual MSS value that should be + uint16_t mss_fix; /**< The actual MSS value that should be * written to the payload packets. This * is the value for IPv4 TCP packets. For * IPv6 packets another 20 bytes must diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 90d85be..bdef703 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -7253,9 +7253,16 @@ VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION); if (p[1]) { + int mssfix =3D positive_atoi(p[1]); + if (mssfix > UINT16_MAX) + { + msg(msglevel, "--mssfix value '%s' is invalid", p[1]); + goto err; + } + /* value specified, assume encapsulation is not * included unless "mtu" follows later */ - options->ce.mssfix =3D positive_atoi(p[1]); + options->ce.mssfix =3D mssfix; options->ce.mssfix_encap =3D false; options->ce.mssfix_default =3D false; } -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/268?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Id8321dfbb8ad8d79f4bb2a9da61f8cd6b6c6ee26 Gerrit-Change-Number: 268 Gerrit-PatchSet: 3 Gerrit-Owner: flichtenheld Gerrit-Reviewer: cron2 Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: cron2 Gerrit-MessageType: newchange --zSUzM+IOPLY= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: cron2, plaisthos.

flichtenheld would like cron2 to review this change.

Vi= ew Change

Change type of frame.mss_fix to uint16_t

Since in the = end this always ends up as an uint16_t
anyway, just make the conversion = much earlier. Cleans
up the code and removes some -Wconversion warnings.=

v2:
- proper error handling in options.c

Change-Id: Id83= 21dfbb8ad8d79f4bb2a9da61f8cd6b6c6ee26
Signed-off-by: Frank Lichtenheld &= lt;frank@...2641...>
---
M src/openvpn/mss.c
M src/openvpn/mss.= h
M src/openvpn/mtu.c
M src/openvpn/mtu.h
M src/openvpn/options.c<= br>5 files changed, 23 insertions(+), 15 deletions(-)

git pull ss=
h://gerrit.openvpn.net:29418/openvpn refs/changes/68/268/3
diff --=
git a/src/openvpn/mss.c b/src/openvpn/mss.c
index dbd3681..= d7ee4c2 100644
--- a/src/openvpn/mss.c
+++ = b/src/openvpn/mss.c
@@ -44,7 +44,7 @@
* = if yes, hand to mss_fixup_dowork()
*/<= br> void
-mss_fix= up_ipv4(struct buffer *buf, int maxmss)
+mss_fixup_ipv4(struct buffer *buf, uint16_t maxmss)
{
const struct openvpn_iphdr *pip;
int hlen;
@@ -72,7 +72,7 @@
struct openvpn_tcphdr *tc =3D (struct openvpn_tcphdr *) BPTR(= &newbuf);

if (tc->flags & OPENVPN_T= CPH_SYN_MASK)
{
- mss_fixup_dowork(&newbuf, (uint1= 6_t) maxmss);
+ = mss_fixup_dowork(&newbuf, maxmss);
= }
}
}
@@ -= 84,7 +84,7 @@
* (IPv6 header structure is su= fficiently different from IPv4...)
*/
vo= id
-mss_fixup_ipv6(stru= ct buffer *buf, int maxmss)
+mss_fixup_ipv6(struct buffer *buf, uint16_t maxmss)
{

const struct openvpn_ipv6hdr *pip6;
struct buffer newbuf;
@@ -130,7 +130,7 @@
= struct openvpn_tcphdr *tc =3D (struct openvpn_tcphdr *) BPTR= (&newbuf);
if (tc->flags & OPENVPN_TCPH= _SYN_MASK)
{
- mss_fixup_dowork(&newbuf, (uint16_t) maxmss= -20);
+ ms= s_fixup_dowork(&newbuf, maxmss-20);
} }
}
@@ -191,13 +191,14 @@
{
contin= ue;
}
- mssval =3D (opt[2]<<8)+opt[3];
+ mssval = =3D opt[2] << 8;
- dmsg(D_MSS, "MSS= : %d -> %d", (int) mssval, (int) maxmss);
+ dmsg(D_MSS, "MSS: %&= quot; PRIu16 " -> %" PRIu16, mssval, maxmss);
= accumulate =3D htons(mssval);
- opt[2] =3D (maxmss>>= 8)&0xff;
- = opt[3] =3D maxmss&0xff;
+ opt[2] =3D (uint8_t)((maxmss>>= 8)&0xff);
+ = opt[3] =3D (uint8_t)(maxmss&0xff);
= accumulate -=3D htons(maxmss);
= ADJUST_CHECKSUM(accumulate, tc->check);
= }
@@ -291,7 +292,7 @@
{
/* we subtract IPv4 and TCP overhead here, mssfix metho= d will add the
* extra 20 for IPv6 */
<= span style=3D"color: hsl(0, 100%, 40%);">- frame->mss_fix =3D opt= ions->ce.mssfix - (20 + 20);

+ frame->mss_fix =3D (uint16_t)(options->ce.mssfix = - (20 + 20));
return;
}

@@ -325,7 +326,7 @@
/* This is the target value our payload needs to be smaller */=
unsigned int target =3D options->ce.mssfix - overh= ead;
- frame->mss= _fix =3D adjust_payload_max_cbc(kt, target) - payload_overhead;
<= span style=3D"color: hsl(120, 100%, 40%);">+ frame->mss_fix =3D (uint= 16_t)(adjust_payload_max_cbc(kt, target) - payload_overhead);



}
diff --git a/src/= openvpn/mss.h b/src/openvpn/mss.h
index 1c4704b..b2a68cf 10= 0644
--- a/src/openvpn/mss.h
+++ b/src/open= vpn/mss.h
@@ -29,9 +29,9 @@
#include "= ;mtu.h"
#include "ssl_common.h"
<= span>

-void mss_fixup_= ipv4(struct buffer *buf, int maxmss);
+void mss_fixup_ipv4(struct buffer *buf, uint16_t maxmss);=

-voi= d mss_fixup_ipv6(struct buffer *buf, int maxmss);
+void mss_fixup_ipv6(struct buffer *buf, uint1= 6_t maxmss);

void mss_fixup_dowork(struc= t buffer *buf, uint16_t maxmss);

diff --g= it a/src/openvpn/mtu.c b/src/openvpn/mtu.c
index 132f93c..3= 89d140 100644
--- a/src/openvpn/mtu.c
+++ b= /src/openvpn/mtu.c
@@ -210,7 +210,7 @@
= buf_printf(&out, "%s ", prefix);
}<= /span>
buf_printf(&out, "[");
- buf_printf(&out, " mss_fix= :%d", frame->mss_fix);
+ buf_printf(&out, " mss_fix:%" PRIu16, frame-&g= t;mss_fix);
#ifdef ENABLE_FRAGMENT
bu= f_printf(&out, " max_frag:%d", frame->max_fragment_size);<= /span>
#endif
diff --git a/src/openvpn/mtu.h b/sr= c/openvpn/mtu.h
index b602b86..c64398d 100644
--- a/src/openvpn/mtu.h

+++ b/src/openvpn/mtu.h@@ -115,7 +115,7 @@
= * decryption/encryption or compression. */
} buf;=

- = unsigned int mss_fix; /**< The actual MSS value that should be
+ uint16_t mss_fix; = /**< The actual MSS value that should be
= * written to the payload packets. This
* is the value for IPv4 TCP = packets. For
* IPv6 pac= kets another 20 bytes must
diff --git a/src/openvpn/options= .c b/src/openvpn/options.c
index 90d85be..bdef703 100644
--- a/src/openvpn/options.c
+++ b/src/openvpn= /options.c
@@ -7253,9 +7253,16 @@
= VERIFY_PERMISSION(OPT_P_GENERAL|OPT_P_CONNECTION);
= if (p[1])
{
+ int mssfix =3D positive_atoi(p[1]);+ if (mssfix > U= INT16_MAX)
+ = {
+ = msg(msglevel, "--mssfix value '%s' is invalid", p[1]);
+ goto = err;
+ }
+
= /* value specified, assume encapsulation is not
= * included unless "mtu" follows later */
- options->ce.mssfix = =3D positive_atoi(p[1]);

+ options->ce.mssfix =3D mssfix;
= options->ce.mssfix_encap =3D false;
op= tions->ce.mssfix_default =3D false;
}

To view, visit change 268. To unsubscribe, or for hel= p writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id8321dfbb8ad8d79f4bb2a9da61= f8cd6b6c6ee26
Gerrit-Change-Number: 268
Gerrit-PatchSet: 3
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: cron2
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: cron2
Gerrit-MessageType: newchange
--zSUzM+IOPLY=--