Fix potential NULL pointer dereference in getIdentitySequence()
authorMichael Paquier <michael@paquier.xyz>
Sun, 26 May 2024 11:58:27 +0000 (20:58 +0900)
committerMichael Paquier <michael@paquier.xyz>
Sun, 26 May 2024 11:58:27 +0000 (20:58 +0900)
commit8285b484a47d829a29fbe0ebe65cdc9f9dfb179d
treeec0a5bd6a8c41407727d6688ba000ccf8eb8fdee
parent945ec4c4bca1e1c4347cd3f93135e96770ac1b4c
Fix potential NULL pointer dereference in getIdentitySequence()

The function invokes SearchSysCacheAttNum() and SearchSysCacheAttName().
They may respectively return 0 for the attribute number or NULL for
the attribute name if the attribute does not exist, without any kind of
error handling.  The common practice is to check that the data retrieved
from the syscache is valid.  There is no risk of NULL pointer
dereferences currently, but let's stick to the practice of making sure
that this data is always valid, to catch future inconsistency mistakes.
The code is switched to use get_attnum() and get_attname(), and adds
some error handling.

Oversight in 509199587df7.

Reported-by: Ranier Vilela
Author: Ashutosh Bapat
Discussion: https://postgr.es/m/CAEudQAqh_RZqoFcYKso5d9VhF-Vd64_ZodfQ_2zSusszkEmyRg@mail.gmail.com
src/backend/catalog/pg_depend.c