Skip to content

Commit bd27319

Browse files
flichtenheldcron2
authored andcommitted
dns: Fix bug in error handling when talking to script
Comparing the result of read/write to a size_t value is dangerous C. Since ssize_t and size_t have the same size ssize_t is promoted to size_t, so -1 becomes size_t max value and is not smaller than the expected length. Make sure to compare ssize_t to ssize_t to avoid any suprises. Change-Id: Ic395b6d1dce510bb4b499c5beba61f033a2a860b Signed-off-by: Frank Lichtenheld <[email protected]> Acked-by: Heiko Hund <[email protected]> Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1208 Message-Id: <[email protected]> URL: https://sourceforge.net/p/openvpn/mailman/message/59238099/ Signed-off-by: Gert Doering <[email protected]>
1 parent 945db23 commit bd27319

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/openvpn/dns.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -642,11 +642,10 @@ run_updown_runner(bool up, struct options *o, const struct tuntap *tt,
642642

643643
while (1)
644644
{
645-
ssize_t rlen, wlen;
646645
char path[PATH_MAX];
647646

648647
/* Block here until parent sends a path */
649-
rlen = read(dns_pipe_fd[0], &path, sizeof(path));
648+
ssize_t rlen = read(dns_pipe_fd[0], &path, sizeof(path));
650649
if (rlen < 1)
651650
{
652651
if (rlen == -1 && errno == EINTR)
@@ -665,8 +664,8 @@ run_updown_runner(bool up, struct options *o, const struct tuntap *tt,
665664
/* Unblock parent process */
666665
while (1)
667666
{
668-
wlen = write(ack_pipe_fd[1], &res, sizeof(res));
669-
if ((wlen == -1 && errno != EINTR) || wlen < sizeof(res))
667+
ssize_t wlen = write(ack_pipe_fd[1], &res, sizeof(res));
668+
if ((wlen == -1 && errno != EINTR) || wlen < (ssize_t)sizeof(res))
670669
{
671670
/* Not much we can do about errors but exit */
672671
close(dns_pipe_fd[0]);
@@ -727,7 +726,7 @@ run_up_down_command(bool up, struct options *o, const struct tuntap *tt,
727726
env_set_write_file(dvf, es);
728727

729728
int wfd = updown_runner->fds[1];
730-
size_t dvf_size = strlen(dvf) + 1;
729+
ssize_t dvf_size = strlen(dvf) + 1;
731730
while (1)
732731
{
733732
ssize_t len = write(wfd, dvf, dvf_size);
@@ -746,7 +745,7 @@ run_up_down_command(bool up, struct options *o, const struct tuntap *tt,
746745
while (1)
747746
{
748747
ssize_t len = read(rfd, &status, sizeof(status));
749-
if (len < sizeof(status))
748+
if (len < (ssize_t)sizeof(status))
750749
{
751750
if (len == -1 && errno == EINTR)
752751
{

0 commit comments

Comments
 (0)