[hackers] [scc] Protect _AT_ and $ in strings when expand macros || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Sat, 3 Oct 2015 12:13:12 +0200 (CEST)

commit 8b96dd8a8d2e271d27d9407d4e847f1d3f194e13
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Sat Oct 3 10:37:47 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Sat Oct 3 12:12:45 2015 +0200

    Protect _AT_ and $ in strings when expand macros
    
    _AT_ and $ are used in the preprocessor to mark
    arguments and concatenation, but they can
    appear in strings, so we have to handle
    strings in copymacro()

diff --git a/cc1/cpp.c b/cc1/cpp.c
index 355ec2c..88f51f6 100644
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
_AT_@ -145,28 +145,39 @@ parsepars(char *buffer, char **listp, int nargs)
         return 1;
 }
 
+/* FIXME: characters in the definition break the macro definition */
 static size_t
 copymacro(char *buffer, char *s, size_t bufsiz, char *arglist[])
 {
- char prevc, c, *arg, *bp = buffer;
+ char prevc, c, *p, *arg, *bp = buffer;
+ size_t size;
 
         for (prevc = '\0'; c = *s; prevc = c, ++s) {
                 if (c != '_AT_') {
- if (c == '#')
- continue;
- if (c == '$') {
+ switch (c) {
+ case '$':
                                 while (bp[-1] == ' ')
                                         --bp, ++bufsiz;
                                 while (s[1] == ' ')
                                         ++s;
+ case '#':
+ continue;
+ case '\"':
+ for (p = s; *++s != '"'; )
+ /* nothing */;
+ size = s - p + 1;
+ if (size > bufsiz)
+ goto expansion_too_long;
+ memcpy(bp, p, size);
+ bufsiz -= size;
+ bp += size;
                                 continue;
+ // case '\'';
                         }
                         if (bufsiz-- == 0)
                                 goto expansion_too_long;
                         *bp++ = c;
                 } else {
- size_t size;
-
                         if (prevc == '#')
                                 bufsiz -= 2;
                         arg = arglist[atoi(++s)];
Received on Sat Oct 03 2015 - 12:13:12 CEST

This archive was generated by hypermail 2.3.0 : Sat Oct 03 2015 - 12:24:13 CEST