diff options
author | Stefan Kempf <stefan@cvs.openbsd.org> | 2016-01-31 13:54:14 +0000 |
---|---|---|
committer | Stefan Kempf <stefan@cvs.openbsd.org> | 2016-01-31 13:54:14 +0000 |
commit | 25eb480671b7fa400c713da935cc314e1c1b8184 (patch) | |
tree | 9a84df547754654fe94ab28046b98ce77131364d /sys | |
parent | 37dbe4e57dd654cacc0d419ee48a2110036b0d29 (diff) |
Convert to ulmin and uiomove to prevent integer truncations.
Reviewed by Martin Natano.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/net/if_pppx.c | 16 | ||||
-rw-r--r-- | sys/net/if_tun.c | 16 |
2 files changed, 18 insertions, 14 deletions
diff --git a/sys/net/if_pppx.c b/sys/net/if_pppx.c index a6a8ac00b89..889eb025d9e 100644 --- a/sys/net/if_pppx.c +++ b/sys/net/if_pppx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_pppx.c,v 1.49 2016/01/14 09:20:31 mpi Exp $ */ +/* $OpenBSD: if_pppx.c,v 1.50 2016/01/31 13:54:13 stefan Exp $ */ /* * Copyright (c) 2010 Claudio Jeker <claudio@openbsd.org> @@ -273,7 +273,8 @@ pppxread(dev_t dev, struct uio *uio, int ioflag) struct pppx_dev *pxd = pppx_dev2pxd(dev); struct mbuf *m, *m0; int error = 0; - int len, s; + int s; + size_t len; if (!pxd) return (ENXIO); @@ -292,9 +293,9 @@ pppxread(dev_t dev, struct uio *uio, int ioflag) } while (m0 != NULL && uio->uio_resid > 0 && error == 0) { - len = min(uio->uio_resid, m0->m_len); + len = ulmin(uio->uio_resid, m0->m_len); if (len != 0) - error = uiomovei(mtod(m0, caddr_t), len, uio); + error = uiomove(mtod(m0, caddr_t), len, uio); m = m_free(m0); m0 = m; } @@ -313,8 +314,9 @@ pppxwrite(dev_t dev, struct uio *uio, int ioflag) uint32_t proto; struct mbuf *top, **mp, *m; struct niqueue *ifq; - int tlen, mlen; + int tlen; int error = 0; + size_t mlen; #if NBPFILTER > 0 int s; #endif @@ -342,8 +344,8 @@ pppxwrite(dev_t dev, struct uio *uio, int ioflag) mp = ⊤ while (error == 0 && uio->uio_resid > 0) { - m->m_len = min(mlen, uio->uio_resid); - error = uiomovei(mtod (m, caddr_t), m->m_len, uio); + m->m_len = ulmin(mlen, uio->uio_resid); + error = uiomove(mtod (m, caddr_t), m->m_len, uio); *mp = m; mp = &m->m_next; if (error == 0 && uio->uio_resid > 0) { diff --git a/sys/net/if_tun.c b/sys/net/if_tun.c index afa6b3d1bcd..88e7b649903 100644 --- a/sys/net/if_tun.c +++ b/sys/net/if_tun.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_tun.c,v 1.165 2016/01/07 05:31:17 guenther Exp $ */ +/* $OpenBSD: if_tun.c,v 1.166 2016/01/31 13:54:13 stefan Exp $ */ /* $NetBSD: if_tun.c,v 1.24 1996/05/07 02:40:48 thorpej Exp $ */ /* @@ -764,7 +764,8 @@ tun_dev_read(struct tun_softc *tp, struct uio *uio, int ioflag) struct ifnet *ifp = &tp->tun_if; struct mbuf *m, *m0; unsigned int ifidx; - int error = 0, len, s; + int error = 0, s; + size_t len; if ((tp->tun_flags & TUN_READY) != TUN_READY) return (EHOSTDOWN); @@ -825,9 +826,9 @@ tun_dev_read(struct tun_softc *tp, struct uio *uio, int ioflag) } while (m0 != NULL && uio->uio_resid > 0 && error == 0) { - len = min(uio->uio_resid, m0->m_len); + len = ulmin(uio->uio_resid, m0->m_len); if (len != 0) - error = uiomovei(mtod(m0, caddr_t), len, uio); + error = uiomove(mtod(m0, caddr_t), len, uio); m = m_free(m0); m0 = m; } @@ -872,7 +873,8 @@ tun_dev_write(struct tun_softc *tp, struct uio *uio, int ioflag) struct niqueue *ifq; u_int32_t *th; struct mbuf *top, **mp, *m; - int error=0, tlen, mlen; + int error = 0, tlen; + size_t mlen; #if NBPFILTER > 0 int s; #endif @@ -911,8 +913,8 @@ tun_dev_write(struct tun_softc *tp, struct uio *uio, int ioflag) m->m_data += ETHER_ALIGN; } while (error == 0 && uio->uio_resid > 0) { - m->m_len = min(mlen, uio->uio_resid); - error = uiomovei(mtod (m, caddr_t), m->m_len, uio); + m->m_len = ulmin(mlen, uio->uio_resid); + error = uiomove(mtod (m, caddr_t), m->m_len, uio); *mp = m; mp = &m->m_next; if (error == 0 && uio->uio_resid > 0) { |