Explicit NULL dereference (src/backend/commands/tablecmds.c)

Started by Ranier Vilelaover 5 years ago2 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

won't retrysuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t44223
psql -h localhost -U postgres

Built from patchset v1 (message #1), July 27, 2026 at 05:03 PM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t44223_1 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t44223_1 && git checkout t44223_1

Patchset v1 (message #1) is on t44223_1

Jump to latest
#1Ranier Vilela
ranier.vf@gmail.com

Hi,

Per Coverity.
CID 1453114 (#1 of 1): Explicit null dereferenced (FORWARD_NULL)
53. var_deref_model: Passing null pointer child_expr to strcmp, which
dereferences it.

It is agreed that asserts should be used for error conditions that can
never occur in the release.
But with errors that can occur, using assert does not make sense.

Better to make sure that strcmp can be called without risk.
Meanwhile, fix the strcmp call signature (const char).

#include <stdio.h>
#include <string.h>

int main()
{
const char * s1="";
const char * s2="0";

if (strstr(s1, s2) != 0) {
printf("found");
} else {
printf("not found");
}
}
not found!

regards,
Ranier Vilela

Attachments:

t44223_1
fix_null_dereference_tablecmds.patchapplication/octet-stream; name=fix_null_dereference_tablecmds.patchDownload+2-4
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Ranier Vilela (#1)
Re: Explicit NULL dereference (src/backend/commands/tablecmds.c)

Ranier Vilela <ranier.vf@gmail.com> writes:

It is agreed that asserts should be used for error conditions that can
never occur in the release.
But with errors that can occur, using assert does not make sense.

On what grounds do you claim that those asserts are wrong?

Coverity's opinion counts for just about nothing these days.
A test case causing a crash would count, of course.

regards, tom lane