Re: small fix to possible null pointer dereference in byteaout() varlena.c

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Grzegorz Jaśkiewicz <gryzman@gmail.com>
Cc: pgsql-hackers@postgresql.org
Date: 2010-09-28T15:23:35Z
Lists: pgsql-hackers
=?UTF-8?Q?Grzegorz_Ja=C5=9Bkiewicz?= <gryzman@gmail.com> writes:
> ...
>                 rp = result = NULL;             /* keep compiler quiet */
>         }
>         *rp = '\0';
> ....

> this strikes me as a clear case of possible null pointer dereference,
> wouldn't you agree ?

No, I wouldn't.  You need to enlarge your peephole by one line:

    else
    {
        elog(ERROR, "unrecognized bytea_output setting: %d",
             bytea_output);
        rp = result = NULL;        /* keep compiler quiet */
    }
    *rp = '\0';

The "keep compiler quiet" line is unreachable code (and that comment is
supposed to remind you of that).

			regards, tom lane