Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4372adf

Browse files
Fix possible NULL pointer dereference in GetNamedDSMSegment().
GetNamedDSMSegment() doesn't check whether dsm_attach() returnsNULL, which creates the possibility of a NULL pointer dereferencesoon after. To fix, emit an ERROR if dsm_attach() returns NULL.This shouldn't happen, but it would be nice to avoid a segfault ifit does. In passing, tidy up the surrounding code.Reported-by: Tom LaneReviewed-by: Michael Paquier, Bharath RupireddyDiscussion:https://postgr.es/m/3348869.1705854106%40sss.pgh.pa.us
1 parentcdd8634 commit4372adf

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

‎src/backend/storage/ipc/dsm_registry.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,19 +177,22 @@ GetNamedDSMSegment(const char *name, size_t size,
177177
(errmsg("requested DSM segment size does not match size of "
178178
"existing segment")));
179179
}
180-
elseif (!dsm_find_mapping(entry->handle))
180+
else
181181
{
182-
/* Attach to existing segment. */
183-
dsm_segment*seg=dsm_attach(entry->handle);
182+
dsm_segment*seg=dsm_find_mapping(entry->handle);
183+
184+
/* If the existing segment is not already attached, attach it now. */
185+
if (seg==NULL)
186+
{
187+
seg=dsm_attach(entry->handle);
188+
if (seg==NULL)
189+
elog(ERROR,"could not map dynamic shared memory segment");
190+
191+
dsm_pin_mapping(seg);
192+
}
184193

185-
dsm_pin_mapping(seg);
186194
ret=dsm_segment_address(seg);
187195
}
188-
else
189-
{
190-
/* Return address of an already-attached segment. */
191-
ret=dsm_segment_address(dsm_find_mapping(entry->handle));
192-
}
193196

194197
dshash_release_lock(dsm_registry_table,entry);
195198
MemoryContextSwitchTo(oldcontext);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp