Re: Unescaped new lines in postgres - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Unescaped new lines in postgres
Date
Msg-id 6214.1006532610@sss.pgh.pa.us
Whole thread Raw
In response to Re: Unescaped new lines in postgres  ("Christopher Kings-Lynne" <chriskl@familyhealth.com.au>)
List pgsql-hackers
"Christopher Kings-Lynne" <chriskl@familyhealth.com.au> writes:
>> From heap.c:
>        /*
>          * sanity checks
>          */
>         if (relname && !allow_system_table_mods &&
>                 IsSystemRelationName(relname) && IsNormalProcessingMode())
>                 elog(ERROR, "invalid relation name \"%s\"; "
>                          "the 'pg_' name prefix is reserved for system
> catalogs",
>                          relname);

> I guess this is a slightly different example than what the issue is below.
> Maybe I'm wrong and the above code is still legal.

This is legal ANSI C.  The spec says that one of the later phases of the
preprocessor is
        6.  Adjacent string literal tokens are concatenated.

I have an old book on C portability that says that this behavior
actually predates the ANSI spec, but wasn't universal in pre-ANSI
compilers.

It's also legal per spec to write
        "invalid relation name \"%s\"; \
the 'pg_' name prefix is reserved for system catalogs",

(note the backslash before the newline) but this strikes me as worse
style since you now have a critical dependency on (a) lack of trailing
whitespace on the first line and (b) lack of leading whitespace on the
second.

What the gcc release note is about is
        "invalid relation name \"%s\"; 
the 'pg_' name prefix is reserved for system catalogs",

Unescaped newlines in string literals are specifically forbidden by
the spec, but apparently gcc takes them anyway.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: v7.2b3 packaged, but not announced beyond here yet ...
Next
From: "Jim Buttafuoco"
Date:
Subject: Re: postgresql.conf (Proposed settings)