From: "flichtenheld (Code Review)" Date: Fri, 16 Jan 2026 15:56:39 +0000 References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: <4367295783f5004eacc5d9f66224de7d6331e2cd-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="wUc1yEq8dFs="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: socket: Fix various conversion warnings List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: openvpn-devel --wUc1yEq8dFs= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: plaisthos. Hello plaisthos, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/1476?usp=3Demail to review the following change. Change subject: socket: Fix various conversion warnings ...................................................................... socket: Fix various conversion warnings - We assume that addrinfo->ai_family always fits into a sa_family_t, so we do not check those. - Reduce places where we explicitly pass ai_family and prefer sock->info.af. - Make sure that --bind-dev has a suitable length. - Treat PROTO_* as uint8_t where possible (however, much code uses proto =3D -1 for various error handling). - Some of the usual "recv* returns ssize_t not int" adaptions. Change-Id: I7be7427480d3540d43dd818eddb6eb5860956459 Signed-off-by: Frank Lichtenheld --- M src/openvpn/options.c M src/openvpn/socket.c M src/openvpn/socket.h M src/openvpn/socket_util.c 4 files changed, 49 insertions(+), 55 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/76/1476/1 diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 85669e0..0f2bd03 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -6515,7 +6515,15 @@ else if (streq(p[0], "bind-dev") && p[1]) { VERIFY_PERMISSION(OPT_P_SOCKFLAGS); - options->bind_dev =3D p[1]; + if (strlen(p[1]) <=3D IFNAMSIZ) + { + options->bind_dev =3D p[1]; + } + else + { + msg(msglevel, "argument to --bind-dev is longer than allowed %= u", IFNAMSIZ); + goto err; + } } #endif else if (streq(p[0], "txqueuelen") && p[1] && !p[2]) @@ -6601,11 +6609,9 @@ } else if (streq(p[0], "proto") && p[1] && !p[2]) { - int proto; - sa_family_t af; VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_CONNECTION); - proto =3D ascii2proto(p[1]); - af =3D ascii2af(p[1]); + int proto =3D ascii2proto(p[1]); + sa_family_t af =3D ascii2af(p[1]); if (proto < 0) { msg(msglevel, "Bad protocol: '%s'. Allowed protocols with --pr= oto option: %s", p[1], diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c index 331249d..eea94d0 100644 --- a/src/openvpn/socket.c +++ b/src/openvpn/socket.c @@ -661,28 +661,23 @@ } static void -bind_local(struct link_socket *sock, const sa_family_t ai_family) +bind_local(struct link_socket *sock) { /* bind to local address/port */ if (sock->bind_local) { if (sock->socks_proxy && sock->info.proto =3D=3D PROTO_UDP) { - socket_bind(sock->ctrl_sd, sock->info.lsa->bind_local, ai_fami= ly, "SOCKS", false); + socket_bind(sock->ctrl_sd, sock->info.lsa->bind_local, sock->i= nfo.af, "SOCKS", false); } else { - socket_bind(sock->sd, sock->info.lsa->bind_local, ai_family, "= TCP/UDP", + socket_bind(sock->sd, sock->info.lsa->bind_local, sock->info.a= f, "TCP/UDP", sock->info.bind_ipv6_only); } } } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - static void create_socket(struct link_socket *sock, struct addrinfo *addr) { @@ -714,7 +709,7 @@ } /* Set af field of sock->info, so it always reflects the address family * of the created socket */ - sock->info.af =3D addr->ai_family; + sock->info.af =3D (sa_family_t)addr->ai_family; /* set socket buffers based on --sndbuf and --rcvbuf options */ socket_set_buffers(sock->sd, &sock->socket_buffer_sizes, true); @@ -726,8 +721,9 @@ if (sock->bind_dev) { msg(M_INFO, "Using bind-dev %s", sock->bind_dev); + /* Note: We verify strlen of bind_dev in options parsing */ if (setsockopt(sock->sd, SOL_SOCKET, SO_BINDTODEVICE, sock->bind_d= ev, - strlen(sock->bind_dev) + 1) + (socklen_t)(strlen(sock->bind_dev) + 1)) !=3D 0) { msg(M_WARN | M_ERRNO, "WARN: setsockopt SO_BINDTODEVICE=3D%s f= ailed", sock->bind_dev); @@ -735,13 +731,9 @@ } #endif - bind_local(sock, addr->ai_family); + bind_local(sock); } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif - #ifdef TARGET_ANDROID static void protect_fd_nonlocal(int fd, const struct sockaddr *addr) @@ -1144,7 +1136,7 @@ static void stream_buf_close(struct stream_buf *sb); -static bool stream_buf_added(struct stream_buf *sb, int length_added); +static bool stream_buf_added(struct stream_buf *sb, ssize_t length_added); /* For stream protocols, allocate a buffer to build up packet. * Called after frame has been finalized. */ @@ -1173,13 +1165,8 @@ } } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - static void -resolve_bind_local(struct link_socket *sock, const sa_family_t af) +resolve_bind_local(struct link_socket *sock) { struct gc_arena gc =3D gc_new(); @@ -1195,12 +1182,12 @@ } /* will return AF_{INET|INET6}from local_host */ - status =3D get_cached_dns_entry(sock->dns_cache, sock->local_host,= sock->local_port, af, + status =3D get_cached_dns_entry(sock->dns_cache, sock->local_host,= sock->local_port, sock->info.af, flags, &sock->info.lsa->bind_local); if (status) { - status =3D openvpn_getaddrinfo(flags, sock->local_host, sock->= local_port, 0, NULL, af, + status =3D openvpn_getaddrinfo(flags, sock->local_host, sock->= local_port, 0, NULL, sock->info.af, &sock->info.lsa->bind_local); } @@ -1221,7 +1208,7 @@ /* the resolved 'local entry' might have a different family th= an * what was globally configured */ - sock->info.af =3D sock->info.lsa->bind_local->ai_family; + sock->info.af =3D (sa_family_t)sock->info.lsa->bind_local->ai_= family; } } @@ -1417,7 +1404,8 @@ sock->mark =3D o->mark; sock->bind_dev =3D o->bind_dev; - sock->info.proto =3D proto; + ASSERT(proto >=3D 0 && proto < PROTO_N); + sock->info.proto =3D (uint8_t)proto; sock->info.af =3D o->ce.af; sock->info.remote_float =3D o->ce.remote_float; sock->info.lsa =3D &c->c1.link_socket_addrs[sock_index]; @@ -1483,7 +1471,7 @@ { if (sock->bind_local) { - resolve_bind_local(sock, sock->info.af); + resolve_bind_local(sock); } resolve_remote(sock, 1, NULL); } @@ -1744,9 +1732,9 @@ * and we should not connect a remote */ if (sock->info.af =3D=3D AF_UNSPEC) { + sock->info.af =3D (sa_family_t)sock->info.lsa->bind_local-= >ai_family; msg(M_WARN, "Could not determine IPv4/IPv6 protocol. Using= %s", - addr_family_name(sock->info.lsa->bind_local->ai_family= )); - sock->info.af =3D sock->info.lsa->bind_local->ai_family; + addr_family_name(sock->info.af)); } create_socket(sock, sock->info.lsa->bind_local); } @@ -2142,12 +2130,13 @@ } static bool -stream_buf_added(struct stream_buf *sb, int length_added) +stream_buf_added(struct stream_buf *sb, ssize_t length_added) { - dmsg(D_STREAM_DEBUG, "STREAM: ADD length_added=3D%d", length_added); + dmsg(D_STREAM_DEBUG, "STREAM: ADD length_added=3D%zd", length_added); if (length_added > 0) { - sb->buf.len +=3D length_added; + ASSERT(sb->buf.len + length_added <=3D INT_MAX); + sb->buf.len +=3D (int)length_added; } /* if length unknown, see if we can get the length prefix from @@ -2253,7 +2242,7 @@ int link_socket_read_tcp(struct link_socket *sock, struct buffer *buf) { - int len =3D 0; + ssize_t len =3D 0; if (!sock->stream_buf.residual_fully_formed) { @@ -2284,7 +2273,7 @@ } if (len <=3D 0) { - return buf->len =3D len; + return buf->len =3D (int)len; } } @@ -2334,13 +2323,14 @@ mesg.msg_name =3D &from->dest.addr; mesg.msg_namelen =3D fromlen; mesg.msg_control =3D pktinfo_buf; - mesg.msg_controllen =3D sizeof pktinfo_buf; - buf->len =3D recvmsg(sock->sd, &mesg, 0); - if (buf->len >=3D 0) + mesg.msg_controllen =3D sizeof(pktinfo_buf); + ssize_t len =3D recvmsg(sock->sd, &mesg, 0); + if (len >=3D 0) { - struct cmsghdr *cmsg; + ASSERT(len <=3D INT_MAX); + buf->len =3D (int)len; fromlen =3D mesg.msg_namelen; - cmsg =3D CMSG_FIRSTHDR(&mesg); + struct cmsghdr *cmsg =3D CMSG_FIRSTHDR(&mesg); if (cmsg !=3D NULL && CMSG_NXTHDR(&mesg, cmsg) =3D=3D NULL #if defined(HAVE_IN_PKTINFO) && defined(HAVE_IPI_SPEC_DST) && cmsg->cmsg_level =3D=3D SOL_IP && cmsg->cmsg_type =3D=3D IP= _PKTINFO @@ -2375,8 +2365,8 @@ else if (cmsg !=3D NULL) { msg(M_WARN, - "CMSG received that cannot be parsed (cmsg_level=3D%d, cms= g_type=3D%d, cmsg=3Dlen=3D%d)", - (int)cmsg->cmsg_level, (int)cmsg->cmsg_type, (int)cmsg->cm= sg_len); + "CMSG received that cannot be parsed (cmsg_level=3D%d, cms= g_type=3D%d, cmsg=3Dlen=3D%zu)", + cmsg->cmsg_level, cmsg->cmsg_type, cmsg->cmsg_len); } } @@ -2403,8 +2393,8 @@ else #endif { - buf->len =3D recvfrom(sock->sd, BPTR(buf), buf_forward_capacity(bu= f), 0, &from->dest.addr.sa, - &fromlen); + buf->len =3D (int)recvfrom(sock->sd, BPTR(buf), buf_forward_capaci= ty(buf), + 0, &from->dest.addr.sa, &fromlen); } /* FIXME: won't do anything when sock->info.af =3D=3D AF_UNSPEC */ if (buf->len >=3D 0 && expectedlen && fromlen !=3D expectedlen) @@ -2423,8 +2413,9 @@ ssize_t link_socket_write_tcp(struct link_socket *sock, struct buffer *buf, struct= link_socket_actual *to) { - packet_size_type len =3D BLEN(buf); - dmsg(D_STREAM_DEBUG, "STREAM: WRITE %d offset=3D%d", (int)len, buf->of= fset); + ASSERT(BLEN(buf) >=3D 0 && BLEN(buf) <=3D PACKET_SIZE_MAX); + packet_size_type len =3D (packet_size_type)BLEN(buf); + dmsg(D_STREAM_DEBUG, "STREAM: WRITE %u offset=3D%d", len, buf->offset); ASSERT(len <=3D sock->stream_buf.maxlen); len =3D htonps(len); ASSERT(buf_write_prepend(buf, &len, sizeof(len))); @@ -2435,10 +2426,6 @@ #endif } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif - #if ENABLE_IP_PKTINFO ssize_t diff --git a/src/openvpn/socket.h b/src/openvpn/socket.h index 850064d..192a03c 100644 --- a/src/openvpn/socket.h +++ b/src/openvpn/socket.h @@ -54,6 +54,7 @@ */ typedef uint16_t packet_size_type; +#define PACKET_SIZE_MAX UINT16_MAX /* convert a packet_size_type from host to network order */ #define htonps(x) htons(x) diff --git a/src/openvpn/socket_util.c b/src/openvpn/socket_util.c index 0194f38..913ac69 100644 --- a/src/openvpn/socket_util.c +++ b/src/openvpn/socket_util.c @@ -356,7 +356,7 @@ const char *short_form; const char *display_form; sa_family_t proto_af; - int proto; + uint8_t proto; }; /* Indexed by PROTO_x */ -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1476?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newchange Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I7be7427480d3540d43dd818eddb6eb5860956459 Gerrit-Change-Number: 1476 Gerrit-PatchSet: 1 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos --wUc1yEq8dFs= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is cur= rently required from: plaisthos.

flichtenheld would like plaisthos to review this change.

V= iew Change

socket: Fix various conversion warnings
=
- We assume that addrinfo->ai_family always fits
into a sa_fami= ly_t, so we do not check those.
- Reduce places where we explicitly pass= ai_family
and prefer sock->info.af.
- Make sure that --bind-dev= has a suitable length.
- Treat PROTO_* as uint8_t where possible (howev= er,
much code uses proto =3D -1 for various error handling).
- Some= of the usual "recv* returns ssize_t not int"
adaptions.
=
Change-Id: I7be7427480d3540d43dd818eddb6eb5860956459
Signed-off-by: = Frank Lichtenheld <frank@...2641...>
---
M src/openvpn/options.= c
M src/openvpn/socket.c
M src/openvpn/socket.h
M src/openvpn/sock= et_util.c
4 files changed, 49 insertions(+), 55 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/change=
s/76/1476/1
diff --git a/src/openvpn/options.c b/src/openvpn/option=
s.c
index 85669e0..0f2bd03 100644
--- a/src= /openvpn/options.c
+++ b/src/openvpn/options.c
@@ -6515,7 +6515,15 @@
else if (streq(p[0], "= bind-dev") && p[1])
{
= VERIFY_PERMISSION(OPT_P_SOCKFLAGS);
- options->bind_dev =3D p[1];
+ if (strlen(p[1]) <=3D IFN= AMSIZ)
+ {
+ options->= ;bind_dev =3D p[1];
+= }
+ el= se
+ {<= br>+ msg(msglevel, &= quot;argument to --bind-dev is longer than allowed %u", IFNAMSIZ);
+ goto err;
+ }
<= span> }

#endif
else if (streq(p[0= ], "txqueuelen") && p[1] && !p[2])
@@ -6601,11 +6609,9 @@

}
else i= f (streq(p[0], "proto") && p[1] && !p[2])<= br> {
- = int proto;
- s= a_family_t af;
VERIFY_PERMISSION(OPT_P_GENERAL | O= PT_P_CONNECTION);
- = proto =3D ascii2proto(p[1]);
- af =3D ascii2af(p[1]);
+ int proto =3D ascii2proto(p[1]);
+ sa_family_t af =3D ascii= 2af(p[1]);

if (proto < 0)
= {
msg(msglevel, "Bad protocol: '%= s'. Allowed protocols with --proto option: %s", p[1],
diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c
index 331249d..eea94d0 100644
--- a/src/openvpn/socket.c<= /span>
+++ b/src/openvpn/socket.c
@@ -661,28 +661,= 23 @@
}

static void
-bind_local(struct link_so= cket *sock, const sa_family_t ai_family)
+bind_local(struct link_socket *sock)
= {
/* bind to local address/port */
= if (sock->bind_local)
{
= if (sock->socks_proxy && sock->info.proto =3D=3D PROTO_UDP)
{
- socket_bind(sock->ctrl_sd, sock->info.lsa->bind_lo= cal, ai_family, "SOCKS", false);
+ socket_bind(sock->ctrl_sd, sock->i= nfo.lsa->bind_local, sock->info.af, "SOCKS", false);=
}
else
= {
- socket_= bind(sock->sd, sock->info.lsa->bind_local, ai_family, "TCP/UD= P",
+ = socket_bind(sock->sd, sock->info.lsa->bind_local, sock->info.a= f, "TCP/UDP",
sock->i= nfo.bind_ipv6_only);
}
}

}

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "= ;-Wconversion"
-#e= ndif
-
= static void
create_socket(struct link_socket *sock, struc= t addrinfo *addr)
{
@@ -714,7 +709,7 @@

}
/* Set af field of sock->info,= so it always reflects the address family
* of the cr= eated socket */
- so= ck->info.af =3D addr->ai_family;
+ sock->info.af =3D (sa_family_t)addr->ai_family= ;

/* set socket buffers based on --s= ndbuf and --rcvbuf options */
socket_set_buffers(sock-= >sd, &sock->socket_buffer_sizes, true);
@@ -726,8= +721,9 @@
if (sock->bind_dev)
= {
msg(M_INFO, "Using bind-dev %s", sock= ->bind_dev);
+ = /* Note: We verify strlen of bind_dev in options parsing */
<= span> if (setsockopt(sock->sd, SOL_SOCKET, SO_BINDTODEVICE, sock= ->bind_dev,
- = strlen(sock->bind_dev) + 1)
+ (socklen_t)(strlen(sock-&= gt;bind_dev) + 1))
!=3D 0)
= {
msg(M_WARN | M_ERRNO, "WARN: sets= ockopt SO_BINDTODEVICE=3D%s failed", sock->bind_dev);
@@ -735,13 +731,9 @@
}
#endif

- bind= _local(sock, addr->ai_family);
+ bind_local(sock);
}

-#if defined(__GNUC__) ||= defined(__clang__)
-#p= ragma GCC diagnostic pop
-
<= span> #ifdef TARGET_ANDROID
static void
p= rotect_fd_nonlocal(int fd, const struct sockaddr *addr)
@@ = -1144,7 +1136,7 @@

static void stream_bu= f_close(struct stream_buf *sb);

-static bool stream_buf_added(struct stream_buf = *sb, int length_added);
+static bool stream_buf_added(struct stream_buf *sb, ssize_t length_adde= d);

/* For stream protocols, allocate a = buffer to build up packet.
* Called after frame has been = finalized. */
@@ -1173,13 +1165,8 @@
}=
}

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push-#pragma GCC diagnostic ignored = "-Wconversion"
-
<= span> static void
-reso= lve_bind_local(struct link_socket *sock, const sa_family_t af)
+resolve_bind_local(struct link_s= ocket *sock)
{
struct gc_arena gc =3D= gc_new();

@@ -1195,12 +1182,12 @@=
}

/* will ret= urn AF_{INET|INET6}from local_host */
- status =3D get_cached_dns_entry(sock->dns_cache,= sock->local_host, sock->local_port, af,
+ status =3D get_cached_dns_entry(sock->= ;dns_cache, sock->local_host, sock->local_port, sock->info.af,
flags, &sock->in= fo.lsa->bind_local);

if (stat= us)
{
- status =3D openvpn_getaddrinfo(flags, sock->local_h= ost, sock->local_port, 0, NULL, af,
+ status =3D openvpn_getaddrinfo(flags, sock-&= gt;local_host, sock->local_port, 0, NULL, sock->info.af,
&sock->info.lsa->bi= nd_local);

}

@@ = -1221,7 +1208,7 @@
/* the resolved 'local = entry' might have a different family than
= * what was globally configured
*/
= - sock->info.af =3D= sock->info.lsa->bind_local->ai_family;
+ sock->info.af =3D (sa_family_t)= sock->info.lsa->bind_local->ai_family;
}<= /span>
}

@@ -1417,7 +1404,8= @@

sock->mark =3D o->mark;

sock->bind_dev =3D o->bind_dev;
- sock->info.proto =3D proto;

+ ASSERT(proto >=3D = 0 && proto < PROTO_N);
+ sock->info.proto =3D (uint8_t)proto;
= sock->info.af =3D o->ce.af;
sock->info.re= mote_float =3D o->ce.remote_float;
sock->info.ls= a =3D &c->c1.link_socket_addrs[sock_index];
@@ -1483= ,7 +1471,7 @@
{
if (sock->= bind_local)
{
- resolve_bind_local(sock, sock->info.af);
+ resolve_bi= nd_local(sock);
}
resolve= _remote(sock, 1, NULL);
}
@@ -1744,9 += 1732,9 @@
* and we should not connect a remot= e */
if (sock->info.af =3D=3D AF_UNSPEC)
{
+ sock->info.af =3D (sa_family_t)sock->info.ls= a->bind_local->ai_family;
msg(M_WARN= , "Could not determine IPv4/IPv6 protocol. Using %s",
<= span style=3D"color: hsl(0, 100%, 40%);">- addr_family_n= ame(sock->info.lsa->bind_local->ai_family));

- sock->info.af =3D sock-&= gt;info.lsa->bind_local->ai_family;
+ addr_family_name(sock->info.af= ));
}
create_sock= et(sock, sock->info.lsa->bind_local);
}
@@ -2142,12 +2130,13 @@
}

static bool
-stream_buf_added(struct stream_buf *sb, int length_added)
+stream_buf_added(struct stream_b= uf *sb, ssize_t length_added)

{
- dmsg(D_STREAM_DEBUG, "STREAM: ADD lengt= h_added=3D%d", length_added);
+ dmsg(D_STREAM_DEBUG, "STREAM: ADD length_added=3D%z= d", length_added);
if (length_added > 0)
{
- = sb->buf.len +=3D length_added;
+ ASSERT(sb->buf.len + length_added <=3D INT_= MAX);
+ sb->= ;buf.len +=3D (int)length_added;
}

/* if length unknown, see if we can get the length pref= ix from
@@ -2253,7 +2242,7 @@
int link_socket_read_tcp(struct link_socket *sock, struct buffer *buf)=
{
- = int len =3D 0;
+ = ssize_t len =3D 0;

if (!sock->st= ream_buf.residual_fully_formed)
{
@@ -= 2284,7 +2273,7 @@
}
if (l= en <=3D 0)
{
- return buf->len =3D len;
+ return buf->len =3D (= int)len;
}
}
=
@@ -2334,13 +2323,14 @@
mesg.msg_nam= e =3D &from->dest.addr;
mesg.msg_namelen =3D fr= omlen;
mesg.msg_control =3D pktinfo_buf;
- mesg.msg_controllen =3D sizeof = pktinfo_buf;

- buf-&= gt;len =3D recvmsg(sock->sd, &mesg, 0);
- if (buf->len >=3D 0)
+ mesg.msg_controllen =3D sizeof(pkti= nfo_buf);
+ ssize_= t len =3D recvmsg(sock->sd, &mesg, 0);
+ if (len >=3D 0)
{
- struct cmsghdr *c= msg;
+ ASSERT(= len <=3D INT_MAX);
+ buf->len =3D (int)len;
fromlen =3D me= sg.msg_namelen;
- = cmsg =3D CMSG_FIRSTHDR(&mesg);
+ struct cmsghdr *cmsg =3D CMSG_FIRSTHDR(&mesg);=
if (cmsg !=3D NULL && CMSG_NXTHDR(&me= sg, cmsg) =3D=3D NULL
#if defined(HAVE_IN_PKTINFO) &&a= mp; defined(HAVE_IPI_SPEC_DST)
&& cmsg= ->cmsg_level =3D=3D SOL_IP && cmsg->cmsg_type =3D=3D IP_PKTIN= FO
@@ -2375,8 +2365,8 @@
else if (= cmsg !=3D NULL)
{
msg= (M_WARN,
- = "CMSG received that cannot be parsed (cmsg_level=3D%d, cmsg_type=3D= %d, cmsg=3Dlen=3D%d)",
- (int)cmsg->cmsg_level, (int)cmsg->cmsg_type, (i= nt)cmsg->cmsg_len);
+ cmsg->cmsg_level, cmsg->cmsg= _type, cmsg->cmsg_len);
}
= }

@@ -2403,8 +2393,8 @@
= else
#endif
{
- buf->len =3D recvfrom(sock->= ;sd, BPTR(buf), buf_forward_capacity(buf), 0, &from->dest.addr.sa,
- = &fromlen);
+= buf->len =3D (int)recvfrom(sock->sd, BPTR(buf), buf_forward_c= apacity(buf),
+ = 0, &from->dest.addr.sa, &fromlen);
}
/* FIXME: won't do anything w= hen sock->info.af =3D=3D AF_UNSPEC */
if (buf->l= en >=3D 0 && expectedlen && fromlen !=3D expectedlen)
@@ -2423,8 +2413,9 @@
ssize_t
link_socket_write_tcp(struct link_socket *sock, struct buffer *buf, stru= ct link_socket_actual *to)

{
- packet_size_type len =3D BLEN(buf);
<= span style=3D"color: hsl(0, 100%, 40%);">- dmsg(D_STREAM_DEBUG, "ST= REAM: WRITE %d offset=3D%d", (int)len, buf->offset);

+ ASSERT(BLEN(buf) >=3D 0 &am= p;& BLEN(buf) <=3D PACKET_SIZE_MAX);

+ packet_size_type len =3D (packet_size_type)BLEN= (buf);
+ dmsg(D_ST= REAM_DEBUG, "STREAM: WRITE %u offset=3D%d", len, buf->offset);=
ASSERT(len <=3D sock->stream_buf.maxlen);
len =3D htonps(len);
ASSERT(buf_write_= prepend(buf, &len, sizeof(len)));
@@ -2435,10 +2426,6 @= @
#endif
}

-#if defined(__GNUC__) || defined(_= _clang__)

-#pragma GCC = diagnostic pop
-#endif<= /span>
-
#if = ENABLE_IP_PKTINFO

ssize_t
diff --git a/src/openvpn/socket.h b/src/openvpn/socket.h

= index 850064d..192a03c 100644
--- a/src/openvpn/socket.h
+++ b/src/openvpn/socket.h
@@ -54,6 +54,7 @@<= /span>
*/

typedef uint16_t pa= cket_size_type;
+#def= ine PACKET_SIZE_MAX UINT16_MAX

/* conver= t a packet_size_type from host to network order */
#define= htonps(x) htons(x)
diff --git a/src/openvpn/socket_util.c = b/src/openvpn/socket_util.c
index 0194f38..913ac69 100644
--- a/src/openvpn/socket_util.c
+++ b/src/op= envpn/socket_util.c
@@ -356,7 +356,7 @@
= const char *short_form;
const char *display_form;
sa_family_t proto_af;
- int proto;
+ uint8_t proto;
};

/* Indexed by PROTO_x */

T= o view, visit change 1476. To unsubscribe, or for help writing mail filters, vi= sit settings= .

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I7be7427480d3540d43dd818eddb= 6eb5860956459
Gerrit-Change-Number: 1476
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
= --wUc1yEq8dFs=--