pppd: Fix bounds check in EAP code
authorPaul Mackerras <paulus@ozlabs.org>
Mon, 3 Feb 2020 04:53:28 +0000 (15:53 +1100)
committerPaul Mackerras <paulus@ozlabs.org>
Mon, 3 Feb 2020 04:53:28 +0000 (15:53 +1100)
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 <ivansprundel@ioactive.com>
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
pppd/eap.c

index 94407f56a336b2d1d0609d67ed5f082a21dd8f63..1b93db01aebd7a2b6ca2dd8ed9848222cacdd997 100644 (file)
@@ -1420,7 +1420,7 @@ int len;
                }
 
                /* Not so likely to happen. */
-               if (vallen >= len + sizeof (rhostname)) {
+               if (len - vallen >= sizeof (rhostname)) {
                        dbglog("EAP: trimming really long peer name down");
                        BCOPY(inp + vallen, rhostname, sizeof (rhostname) - 1);
                        rhostname[sizeof (rhostname) - 1] = '\0';
@@ -1846,7 +1846,7 @@ int len;
                }
 
                /* Not so likely to happen. */
-               if (vallen >= len + sizeof (rhostname)) {
+               if (len - vallen >= sizeof (rhostname)) {
                        dbglog("EAP: trimming really long peer name down");
                        BCOPY(inp + vallen, rhostname, sizeof (rhostname) - 1);
                        rhostname[sizeof (rhostname) - 1] = '\0';