From 2ee3cbe69c6d2805e64e7cac2a1c1706e49ffd86 Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Mon, 10 Feb 2020 23:21:35 +0100 Subject: [PATCH] PPP, EAP: fix bounds check in EAP code Given that we have just checked vallen < len, it can never be the case that vallen >= len + sizeof(rhostname). This fixes the check so we actually avoid overflowing the rhostname array. Reported-by: Ilja Van Sprundel Signed-off-by: Paul Mackerras Signed-off-by: Sylvain Rochet (compiler warning fix about int vs uint comparisons) --- src/netif/ppp/eap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/netif/ppp/eap.c b/src/netif/ppp/eap.c index 87871666..ee2997c6 100644 --- a/src/netif/ppp/eap.c +++ b/src/netif/ppp/eap.c @@ -1417,7 +1417,7 @@ static void eap_request(ppp_pcb *pcb, u_char *inp, int id, int len) { } /* Not so likely to happen. */ - if (vallen >= len + sizeof (rhostname)) { + if (len - vallen >= (int)sizeof (rhostname)) { ppp_dbglog(("EAP: trimming really long peer name down")); MEMCPY(rhostname, inp + vallen, sizeof (rhostname) - 1); rhostname[sizeof (rhostname) - 1] = '\0'; @@ -1845,7 +1845,7 @@ static void eap_response(ppp_pcb *pcb, u_char *inp, int id, int len) { } /* Not so likely to happen. */ - if (vallen >= len + sizeof (rhostname)) { + if (len - vallen >= (int)sizeof (rhostname)) { ppp_dbglog(("EAP: trimming really long peer name down")); MEMCPY(rhostname, inp + vallen, sizeof (rhostname) - 1); rhostname[sizeof (rhostname) - 1] = '\0';