Potential NULL dereference in pag.cpp?

11 views
Skip to first unread message

Mark Rotteveel

unread,
Aug 7, 2025, 7:31:56 AMAug 7
to firebir...@googlegroups.com
Visual Studio warns about a possible NULL dereference in pag.cpp,
function PAG_release_pages. Specifically on line 1372, as pages could be
NULL if cntRelease <= 0.

I'm not sure if that can happen in practice, but the logic in some of
some of the callers is complicated enough that I cannot exclude the
possibility that it might be 0.

What would be the proper fix here? Add a guard clause at the function
start to return early if cntRelease <= 0? Or modify the condition on
line 1372 to
```
if (pages && pages->pip_extent < pageMgr.pagesPerPIP)
```
or something else?

Mark
--
Mark Rotteveel

Vlad Khorsun

unread,
Aug 7, 2025, 7:39:52 AMAug 7
to firebir...@googlegroups.com
07.08.2025 14:31, 'Mark Rotteveel' via firebird-devel:
> Visual Studio warns about a possible NULL dereference in pag.cpp, function PAG_release_pages. Specifically on line 1372, as pages
> could be NULL if cntRelease <= 0.
>
> I'm not sure if that can happen in practice, but the logic in some of some of the callers is complicated enough that I cannot
> exclude the possibility that it might be 0.

cntRelease is a number of pages to release. Of course, it must be > 0.

> What would be the proper fix here? Add a guard clause at the function start to return early if cntRelease <= 0?

Yes, it should be enough and should not harm performance.
And fb_assert() to catch such "impossible" case in DEBUG build, please.

Regards,
Vlad
Reply all
Reply to author
Forward
0 new messages