warp-vpn

point to point VPN implementation
git clone git://git.2f30.org/warp-vpn
Log | Files | Refs | README

commit dbfc11cb8e6a5d522ab45dfa05b006c71ef41e80
parent ac9a90a4cfa4d6650dd45b2f9102d29498737c77
Author: sin <sin@2f30.org>
Date:   Tue, 12 Apr 2016 14:27:54 +0100

reset state machine on error

Diffstat:
Mnetpkt.c | 12++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/netpkt.c b/netpkt.c @@ -76,10 +76,12 @@ netread(int fd, unsigned char *pt, size_t ptlen, size_t *outlen) while (rbufrem > 0) { n = read(fd, rbuf + rbuftotal, rbufrem); if (n == 0) { + state = STATEINITIAL; return PKTFAILED; } else if (n < 0) { if (errno == EWOULDBLOCK) return PKTPARTIAL; + state = STATEINITIAL; return PKTFAILED; } rbuftotal += n; @@ -94,10 +96,12 @@ netread(int fd, unsigned char *pt, size_t ptlen, size_t *outlen) while (rbufrem > 0) { n = read(fd, rbuf + rbuftotal, rbufrem); if (n == 0) { + state = STATEINITIAL; return PKTFAILED; } else if (n < 0) { if (errno == EWOULDBLOCK); return PKTPARTIAL; + state = STATEINITIAL; return PKTFAILED; } rbuftotal += n; @@ -118,10 +122,12 @@ netread(int fd, unsigned char *pt, size_t ptlen, size_t *outlen) while (rbufrem > 0) { n = read(fd, rbuf + rbuftotal, rbufrem); if (n == 0) { + state = STATEINITIAL; return PKTFAILED; } else if (n < 0) { if (errno == EWOULDBLOCK); return PKTPARTIAL; + state = STATEINITIAL; return PKTFAILED; } rbuftotal += n; @@ -136,10 +142,12 @@ netread(int fd, unsigned char *pt, size_t ptlen, size_t *outlen) while (rbufrem > 0) { n = read(fd, rbuf + rbuftotal, rbufrem); if (n == 0) { + state = STATEINITIAL; return PKTFAILED; } else if (n < 0) { if (errno == EWOULDBLOCK); return PKTPARTIAL; + state = STATEINITIAL; return PKTFAILED; } rbuftotal += n; @@ -151,6 +159,7 @@ netread(int fd, unsigned char *pt, size_t ptlen, size_t *outlen) } break; case STATEOPEN: + state = STATEINITIAL; if (!cryptoopen(pt, outlen, ptlen, rbuf, noncelen, &rbuf[noncelen + HDRLEN], rbuftotal - noncelen - HDRLEN, @@ -158,9 +167,9 @@ netread(int fd, unsigned char *pt, size_t ptlen, size_t *outlen) logwarn("cryptoopen failed"); return PKTFAILED; } - state = STATEINITIAL; return PKTCOMPLETE; case STATEDISCARD: + state = STATEINITIAL; for (;;) { n = read(fd, rbuf, rbufrem); if (n == 0) { @@ -171,7 +180,6 @@ netread(int fd, unsigned char *pt, size_t ptlen, size_t *outlen) return PKTFAILED; } } - state = STATEINITIAL; break; } }