Subject: Re: null iv parameter passed to combo_init()

From: Zhihong Yu <[email-masked]>
Date: Sun, 9 Jan 2022 04:37:32 -0800

On Sat, Jan 8, 2022 at 11:32 PM Tom Lane <[email-masked]> wrote:

> Noah Misch <[email-masked]> writes:
> > On further thought, I would write it this way:
>
> > -             else
> > +             else if (ivlen != 0)
> >                       memcpy(ivbuf, iv, ivlen);
>
> FWIW, I liked the "ivlen > 0" formulation better.  They should be
> equivalent, because ivlen is unsigned, but it just seems like "> 0"
> is more natural.
>
>                         regards, tom lane
>

Patch v4 is attached.

Cheers

---

From: Noah Misch <[email-masked]>
Date: Sun, 9 Jan 2022 08:48:54 -0800

> > equivalent, because ivlen is unsigned, but it just seems like "> 0"

If I were considering the one code site in isolation, I'd pick "ivlen > 0".
But of the four sites identified so far, three have signed length variables.
Since we're likely to get more examples of this pattern, some signed and some
unsigned, I'd rather use a style that does the optimal thing whether or not
the variable is signed.  What do you think?

> Patch v4 is attached.

Does this pass the test procedure shown upthread?

---

From: Tom Lane <[email-masked]>
Date: Sun, 09 Jan 2022 11:51:16 -0500

> But of the four sites identified so far, three have signed length variables.

Oh, hmm.  Unless we want to start changing those to unsigned, I agree
a not-equal test is a safer convention.

			regards, tom lane

---

From: Zhihong Yu <[email-masked]>
Date: Sun, 9 Jan 2022 12:38:23 -0800

> Does this pass the test procedure shown upthread?
Hi,
I installed gcc 4.9.3

When I ran:
./configure CFLAGS='-fsanitize=undefined
-fsanitize-undefined-trap-on-error'

I saw:

configure:3977: $? = 0
configure:3966: gcc -V >&5
gcc: error: unrecognized command line option '-V'
gcc: fatal error: no input files
compilation terminated.
configure:3977: $? = 1
configure:3966: gcc -qversion >&5
gcc: error: unrecognized command line option '-qversion'
gcc: fatal error: no input files
compilation terminated.
configure:3977: $? = 1
configure:3997: checking whether the C compiler works
configure:4019: gcc -fsanitize=undefined -fsanitize-undefined-trap-on-error
  conftest.c  >&5
gcc: error: unrecognized command line option
'-fsanitize-undefined-trap-on-error'
configure:4023: $? = 1
configure:4061: result: no

I wonder if a higher version gcc is needed.

FYI

---

From: Zhihong Yu <[email-masked]>
Date: Sun, 9 Jan 2022 13:27:27 -0800

On Sun, Jan 9, 2022 at 12:38 PM Zhihong Yu <[email-masked]> wrote:

> configure:4019: gcc -fsanitize=undefined
> -fsanitize-undefined-trap-on-error   conftest.c  >&5

After installing gcc-11, ./configure passed (with 0003-memcpy-null.patch).
In the output of `make check-world`, I don't see `runtime error`.
Though there was a crash (maybe specific to my machine):

Core was generated by
`/nfusr/dev-server/zyu/postgres/tmp_install/usr/local/pgsql/bin/postgres
--singl'.
Program terminated with signal SIGILL, Illegal instruction.
#0  0x000000000050642d in write_item.cold ()
Missing separate debuginfos, use: debuginfo-install
glibc-2.17-325.el7_9.x86_64 nss-pam-ldapd-0.8.13-25.el7.x86_64
sssd-client-1.16.5-10.el7_9.10.x86_64
(gdb) bt
#0  0x000000000050642d in write_item.cold ()
#1  0x0000000000ba9d1b in write_relcache_init_file ()
#2  0x0000000000bb58f7 in RelationCacheInitializePhase3 ()
#3  0x0000000000bd5cb5 in InitPostgres ()
#4  0x0000000000a0a9ea in PostgresMain ()

FYI