From: "flichtenheld (Code Review)"
Date: Tue, 20 Jan 2026 17:48:42 +0000
In-Reply-To:
References:
Reply-To: frank@...2641..., arne-openvpn@...1227...,
openvpn-devel@lists.sourceforge.net
Message-ID: <95767954d67cd0b136647bdf04a1daafaa040aea-EmailReplacePatchSet-HTML@...2715...>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
Content-Type: multipart/alternative; boundary="Zg2v4pHiYyQ="; 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
--Zg2v4pHiYyQ=
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 reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/1476?usp=3Demail
to look at the new patch set (#4).
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, 50 insertions(+), 55 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/76/1476/4
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..a214093 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 @@
=20
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,15 @@
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 (socklen_t)sizeof(pktinfo_buf);
+ ssize_t len =3D recvmsg(sock->sd, &mesg, 0);
+ ASSERT(len >=3D INT_MIN && len <=3D INT_MAX);
+ /* Note that we communicate recvmsg failure to caller here */
+ buf->len =3D (int)len;
+ if (len >=3D 0)
{
- struct cmsghdr *cmsg;
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 +2366,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, (size_t)cmsg->cmsg_len);
}
}
@@ -2403,8 +2394,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 +2414,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 +2427,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: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I7be7427480d3540d43dd818eddb6eb5860956459
Gerrit-Change-Number: 1476
Gerrit-PatchSet: 4
Gerrit-Owner: flichtenheld
Gerrit-Reviewer: flichtenheld
Gerrit-Reviewer: plaisthos
Gerrit-CC: openvpn-devel
Gerrit-Attention: plaisthos
--Zg2v4pHiYyQ=
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Attention is cur=
rently required from: plaisthos.
flichtenheld uploaded patch set #4 to this change.
<=
p>View C=
hange
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_f=
amily 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 t=
he usual "recv* returns ssize_t not int" adaptions. C=
hange-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/socket_ut=
il.c 4 files changed, 50 insertions(+), 55 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/76/=
1476/4diff --git a/src/openvpn/options.c b/src/openvpn/options.c=
span>index 85669e0..0f2bd03 100644 --- a/src/open=
vpn/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], &q=
uot;txqueuelen") && p[1] && !p[2]) @@ =
-6601,11 +6609,9 @@ } else if (st=
req(p[0], "proto") && p[1] && !p[2]) { - int=
proto; - sa_fam=
ily_t af; VERIFY_PERMISSION(OPT_P_GENERAL | OPT_P_=
CONNECTION); - p=
roto =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 --proto option: %s", p[1], d=
iff --git a/src/openvpn/socket.c b/src/openvpn/socket.c ind=
ex 331249d..a214093 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 (s=
ock->socks_proxy && sock->info.proto =3D=3D PROTO_UDP) =
{ - =
socket_bind(sock->ctrl_sd, sock->info.lsa->bind_local, =
ai_family, "SOCKS", false); + socket_bind(sock->ctrl_sd, sock->info.l=
sa->bind_local, sock->info.af, "SOCKS", false); <=
span> } else {- socket_bind(=
sock->sd, sock->info.lsa->bind_local, ai_family, "TCP/UDP&quo=
t;, + sock=
et_bind(sock->sd, sock->info.lsa->bind_local, sock->info.af, &q=
uot;TCP/UDP", sock->info.b=
ind_ipv6_only); } } } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wco=
nversion" -#endif<=
/span>- stat=
ic void create_socket(struct link_socket *sock, struct add=
rinfo *addr) { @@ -714,7 +709,7 @@ <=
br> } /* Set af field of sock->info, so i=
t always reflects the address family * of the created=
socket */ - sock-&g=
t;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->s=
d, &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_dev, - =
strlen(sock->bind_dev) + 1) + (socklen_t)(strlen(sock->bi=
nd_dev) + 1)) !=3D 0) =
{ msg(M_WARN | M_ERRNO, "WARN: setsockop=
t SO_BINDTODEVICE=3D%s failed", sock->bind_dev); @@=
-735,13 +731,9 @@ } #endif - bind_loca=
l(sock, addr->ai_family); + bind_local(sock); } <=
br>-#if defined(__GNUC__) || defi=
ned(__clang__) -#pragma=
GCC diagnostic pop -#e=
ndif - =
#ifdef TARGET_ANDROID static void protec=
t_fd_nonlocal(int fd, const struct sockaddr *addr) @@ -1144=
,7 +1136,7 @@ static void stream_buf_clo=
se(struct stream_buf *sb); -static bool stream_buf_added(struct stream_buf *sb, =
int length_added); +s=
tatic bool stream_buf_added(struct stream_buf *sb, ssize_t length_added);=
span> /* For stream protocols, allocate a buffe=
r to build up packet. * Called after frame has been final=
ized. */ @@ -1173,13 +1165,8 @@ } } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "=
;-Wconversion" -#e=
ndif - =
static void -resolve_b=
ind_local(struct link_socket *sock, const sa_family_t af) +resolve_bind_local(struct link_socket=
*sock) { struct gc_arena gc =3D gc_n=
ew(); @@ -1195,12 +1182,12 @@ <=
span> } /* will return A=
F_{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.ls=
a->bind_local); if (status)=
span> { - status =3D openvpn_getaddrinfo(flags, sock->local_host, =
sock->local_port, 0, NULL, af, + status =3D openvpn_getaddrinfo(flags, sock->lo=
cal_host, sock->local_port, 0, NULL, sock->info.af, =
&sock->info.lsa->bind_lo=
cal); } @@ -1221=
,7 +1208,7 @@ /* the resolved 'local entry=
' might have a different family than * wh=
at 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 @@=
span> sock->mark =3D o->mark; <=
br> sock->bind_dev =3D o->bind_dev; - sock->info.proto =3D proto; + ASSERT(proto >=3D 0 &=
amp;& proto < PROTO_N); + sock->info.proto =3D (uint8_t)proto; =
sock->info.af =3D o->ce.af; sock->info.remot=
e_float =3D o->ce.remote_float; sock->info.lsa =
=3D &c->c1.link_socket_addrs[sock_index]; @@ -1483,7=
+1471,7 @@ { if (sock->bi=
nd_local) { - resolve_bind_local(sock, sock->info.af);+ resolve_bind=
_local(sock); } resolve_r=
emote(sock, 1, NULL); } @@ -1744,9 +17=
32,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_nam=
e(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; } =
span> /* 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,15 @@ 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 (socklen_t)=
sizeof(pktinfo_buf); =
+ ssize_t len =3D recvmsg(sock->sd, &mesg, 0); + ASSERT(len >=3D INT_MIN &&a=
mp; len <=3D INT_MAX); + /* Note that we communicate recvmsg failure to caller here */+ buf->len =3D (in=
t)len; + if (len &=
gt;=3D 0) { - struct cmsghdr *cmsg; fromlen =
=3D mesg.msg_namelen; -=
cmsg =3D CMSG_FIRSTHDR(&mesg); + struct cmsghdr *cmsg =3D CMSG_FIRSTHDR(&=
mesg); if (cmsg !=3D NULL && CMSG_NXTHDR(&=
amp;mesg, cmsg) =3D=3D NULL #if defined(HAVE_IN_PKTINFO) &=
amp;& defined(HAVE_IPI_SPEC_DST) &&=
; cmsg->cmsg_level =3D=3D SOL_IP && cmsg->cmsg_type =3D=3D IP=
_PKTINFO @@ -2375,8 +2366,8 @@ els=
e if (cmsg !=3D NULL) { =
msg(M_WARN, - =
"CMSG received that cannot be parsed (cmsg_level=3D%d, cmsg_t=
ype=3D%d, cmsg=3Dlen=3D%d)", - (int)cmsg->cmsg_level, (int)cmsg->cmsg_ty=
pe, (int)cmsg->cmsg_len); + "CMSG received that cannot be parsed (cmsg_le=
vel=3D%d, cmsg_type=3D%d, cmsg=3Dlen=3D%zu)", + cmsg->cmsg_level, cmsg-&g=
t;cmsg_type, (size_t)cmsg->cmsg_len); } <=
br> } @@ -2403,8 +2394,8 @@ else #endif { - buf->len =3D rec=
vfrom(sock->sd, BPTR(buf), buf_forward_capacity(buf), 0, &from->d=
est.addr.sa, - =
&fromlen); + buf->len =3D (int)recvfrom(sock->sd, BPTR(buf),=
buf_forward_capacity(buf), + 0, &from->dest.addr.sa, &am=
p;fromlen); } /* FIXME: won't=
do anything when sock->info.af =3D=3D AF_UNSPEC */ =
if (buf->len >=3D 0 && expectedlen && fromlen !=3D e=
xpectedlen) @@ -2423,8 +2414,9 @@ ssize_t<=
/span> link_socket_write_tcp(struct link_socket *sock, struct buf=
fer *buf, struct link_socket_actual *to) { - packet_size_type len =3D BLEN(buf=
); - dmsg(D_STREAM_D=
EBUG, "STREAM: WRITE %d offset=3D%d", (int)len, buf->offset);<=
/span>+ 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, bu=
f->offset); ASSERT(len <=3D sock->stream_buf.=
maxlen); len =3D htonps(len); ASS=
ERT(buf_write_prepend(buf, &len, sizeof(len))); @@ -243=
5,10 +2427,6 @@ #endif } =
-#if defined(__GNUC__=
) || defined(__clang__) -#pragma GCC diagnostic pop -#endif - <=
br> #if ENABLE_IP_PKTINFO ssize_t<=
/span>diff --git a/src/openvpn/socket.h b/src/openvpn/socket.hindex 850064d..192a03c 100644 --- a/src/openv=
pn/socket.h +++ b/src/openvpn/socket.h @@ -=
54,6 +54,7 @@ */ typed=
ef 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..91=
3ac69 100644 --- a/src/openvpn/socket_util.c +++ b/src/openvpn/socket_util.c @@ -356,7 +356,7 @@ const char *short_form; const char *di=
splay_form; sa_family_t proto_af; - int proto; + uint8_t proto; }; /* Indexed by PROTO_x */ =
To view, visit change 1476 . To unsubscribe, or for help writing ma=
il filters, visit settings .
=
div>
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I7be7427480d3540d43dd818eddb=
6eb5860956459
Gerrit-Change-Number: 1476
Gerrit-PatchSet: 4
Gerrit-Owner: flichtenheld <frank@...2723...=
.>
Gerrit-Reviewer: flichtenheld <frank@...2716...=
1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...=
.1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...=
ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...=
..1227...>
=
--Zg2v4pHiYyQ=--