From: Michael Meskes Date: Fri, 5 Jul 2013 09:07:16 +0000 (+0200) Subject: Apploed patch by MauMau to escape filenames in #line statements. X-Git-Tag: REL9_4_BETA1~1367 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9ce9dfdb999960aa7596bb219db02ccdbe2da855;p=postgresql Apploed patch by MauMau to escape filenames in #line statements. --- diff --git a/src/interfaces/ecpg/preproc/output.c b/src/interfaces/ecpg/preproc/output.c index 389a5272d4..616e8f0400 100644 --- a/src/interfaces/ecpg/preproc/output.c +++ b/src/interfaces/ecpg/preproc/output.c @@ -95,9 +95,22 @@ hashline_number(void) #endif ) { - char *line = mm_alloc(strlen("\n#line %d \"%s\"\n") + sizeof(int) * CHAR_BIT * 10 / 3 + strlen(input_filename)); - - sprintf(line, "\n#line %d \"%s\"\n", yylineno, input_filename); + /* "* 2" here is for escaping \s below */ + char *line = mm_alloc(strlen("\n#line %d \"%s\"\n") + sizeof(int) * CHAR_BIT * 10 / 3 + strlen(input_filename) * 2); + char *src, + *dest; + + sprintf(line, "\n#line %d \"", yylineno); + src = input_filename; + dest = line + strlen(line); + while (*src) + { + if (*src == '\\') + *dest++ = '\\'; + *dest++ = *src++; + } + *dest = '\0'; + strcat(dest, "\"\n"); return line; }