mirror of
https://github.com/postgres/postgres.git
synced 2025-04-29 13:56:47 +03:00
Fix possible NULL pointer dereference in GetNamedDSMSegment().
GetNamedDSMSegment() doesn't check whether dsm_attach() returns NULL, which creates the possibility of a NULL pointer dereference soon after. To fix, emit an ERROR if dsm_attach() returns NULL. This shouldn't happen, but it would be nice to avoid a segfault if it does. In passing, tidy up the surrounding code. Reported-by: Tom Lane Reviewed-by: Michael Paquier, Bharath Rupireddy Discussion: https://postgr.es/m/3348869.1705854106%40sss.pgh.pa.us
This commit is contained in:
parent
cdd863480c
commit
4372adfa24
@ -177,18 +177,21 @@ GetNamedDSMSegment(const char *name, size_t size,
|
|||||||
(errmsg("requested DSM segment size does not match size of "
|
(errmsg("requested DSM segment size does not match size of "
|
||||||
"existing segment")));
|
"existing segment")));
|
||||||
}
|
}
|
||||||
else if (!dsm_find_mapping(entry->handle))
|
|
||||||
{
|
|
||||||
/* Attach to existing segment. */
|
|
||||||
dsm_segment *seg = dsm_attach(entry->handle);
|
|
||||||
|
|
||||||
dsm_pin_mapping(seg);
|
|
||||||
ret = dsm_segment_address(seg);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Return address of an already-attached segment. */
|
dsm_segment *seg = dsm_find_mapping(entry->handle);
|
||||||
ret = dsm_segment_address(dsm_find_mapping(entry->handle));
|
|
||||||
|
/* If the existing segment is not already attached, attach it now. */
|
||||||
|
if (seg == NULL)
|
||||||
|
{
|
||||||
|
seg = dsm_attach(entry->handle);
|
||||||
|
if (seg == NULL)
|
||||||
|
elog(ERROR, "could not map dynamic shared memory segment");
|
||||||
|
|
||||||
|
dsm_pin_mapping(seg);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = dsm_segment_address(seg);
|
||||||
}
|
}
|
||||||
|
|
||||||
dshash_release_lock(dsm_registry_table, entry);
|
dshash_release_lock(dsm_registry_table, entry);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user