[hackers] [scc] Avoid accessing beyond end of string || Michael Forney

From: <git_AT_suckless.org>
Date: Thu, 16 Feb 2017 09:58:10 +0100 (CET)

commit 1dfb93dc4b91b4c3e5186757965a42595e142b9a
Author: Michael Forney <mforney_AT_mforney.org>
AuthorDate: Wed Feb 15 23:55:31 2017 -0800
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Thu Feb 16 09:56:22 2017 +0100

    Avoid accessing beyond end of string
    
    When bp == lim, we should not dereference bp since it lies beyond the
    allocated memory.

diff --git a/cc1/code.c b/cc1/code.c
index c4ce697..01bf6ff 100644
--- a/cc1/code.c
+++ b/cc1/code.c
_AT_@ -317,7 +317,7 @@ emitstring(Symbol *sym, Type *tp)
         lim = &sym->u.s[tp->n.elem];
         while (bp < lim) {
                 s = bp;
- while (isprint(*bp) && bp < lim)
+ while (bp < lim && isprint(*bp))
                         ++bp;
                 if ((n = bp - s) > 1)
                         fprintf(outfp, "\t#\"%.*s\n", n, s);
_AT_@ -329,7 +329,7 @@ emitstring(Symbol *sym, Type *tp)
                         fprintf(outfp,
                                 "\t#%c%02X\n",
                                 chartype->letter, (*bp++) & 0xFF);
- } while (!isprint(*bp) && bp < lim);
+ } while (bp < lim && !isprint(*bp));
         }
 }
 
Received on Thu Feb 16 2017 - 09:58:10 CET

This archive was generated by hypermail 2.3.0 : Thu Feb 16 2017 - 10:00:20 CET