Potential null pointer dereference in postgres.c
Hi hackers,
When backporting 66e94448 to older versions it was forgotten to check
malloc() result. In 16+ versions guc_malloc() is used to allocate
memory and it checks if the result pointer is NULL, so there is no
need to check it after guc_malloc(). Versions before 16 have no
guc_malloc(), and malloc() is used instead, but we have to check if
return value is NULL.
Please find attached patch for REL_15_STABLE. This should be fixed in
older versions too.
Best regards,
Karina Litskevich
Postgres Professional: http://postgrespro.com/
Attachments:
v1-0001-Check-if-malloc-returned-NULL.patchtext/x-patch; charset=US-ASCII; name=v1-0001-Check-if-malloc-returned-NULL.patchDownload+6-1
Karina Litskevich <litskevichkarina@gmail.com> writes:
When backporting 66e94448 to older versions it was forgotten to check
malloc() result. In 16+ versions guc_malloc() is used to allocate
memory and it checks if the result pointer is NULL, so there is no
need to check it after guc_malloc(). Versions before 16 have no
guc_malloc(), and malloc() is used instead, but we have to check if
return value is NULL.
Yup, you're right. Thanks for the report!
regards, tom lane
I'm glad you are bringing up this issue. By the way, there are two more
annoying places in postmaster.c for pg16 and older. See, strdup() also may
fail if insufficient memory available.
PFA patch for a REL_16_STABLE. It also applies to older versions.
--
Best regards,
Maxim Orlov.
Attachments:
v2-0001-Use-pstrdup-for-remote_host-and-remote_port-save-.patchapplication/octet-stream; name=v2-0001-Use-pstrdup-for-remote_host-and-remote_port-save-.patchDownload+2-3
I have to admit I was wrong with previous v2 patch. Sorry.
Apparently, the chances of committing this very low, but here is the
correct one.
--
Best regards,
Maxim Orlov.