postgresql/src/backend/utils/activity
Michael Paquier f91c87b314 Avoid memory size overflow when allocating backend activity buffer
The code in charge of copying the contents of PgBackendStatus to local
memory could fail on memory allocation because of an overflow on the
amount of memory to use.  The overflow can happen when combining a high
value track_activity_query_size (max at 1MB) with a large
max_connections, when both multiplied get higher than INT32_MAX as both
parameters treated as signed integers.  This could for example trigger
with the following functions, all calling pgstat_read_current_status():
- pg_stat_get_backend_subxact()
- pg_stat_get_backend_idset()
- pg_stat_get_progress_info()
- pg_stat_get_activity()
- pg_stat_get_db_numbackends()

The change to use MemoryContextAllocHuge() has been introduced in
8d0ddccec6, so backpatch down to 12.

Author: Jakub Wartak
Discussion: https://postgr.es/m/CAKZiRmw8QSNVw2qNK-dznsatQqz+9DkCquxP0GHbbv1jMkGHMA@mail.gmail.com
Backpatch-through: 12
2023-10-03 15:37:21 +09:00
..
Makefile Split backend status and progress related functionality out of pgstat.c. 2021-04-03 11:42:52 -07:00
backend_progress.c Initial pgindent and pgperltidy run for v14. 2021-05-12 13:14:10 -04:00
backend_status.c Avoid memory size overflow when allocating backend activity buffer 2023-10-03 15:37:21 +09:00
wait_event.c Fix waiting in RegisterSyncRequest(). 2022-03-16 15:35:42 +13:00