mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-20 05:11:26 +02:00
BUG/MINOR: halog: Add OOM checks for calloc() in filter_count_srv_status() and filter_count_url()
This patch adds missing out-of-memory (OOM) checks after calls to calloc() in the functions `filter_count_srv_status()` and `filter_count_url()`. If memory allocation fails, an error message is printed to stderr and the process exits with status 1. This improves robustness and prevents undefined behavior in low-memory situations. Co-authored-by: Christian Norbert Menges <christian.norbert.menges@sap.com>
This commit is contained in:
parent
8c555a4a4e
commit
fbd0fb20a2
@ -1571,6 +1571,10 @@ void filter_count_srv_status(const char *accept_field, const char *time_field, s
|
|||||||
if (!srv_node) {
|
if (!srv_node) {
|
||||||
/* server not yet in the tree, let's create it */
|
/* server not yet in the tree, let's create it */
|
||||||
srv = (void *)calloc(1, sizeof(struct srv_st) + e - b + 1);
|
srv = (void *)calloc(1, sizeof(struct srv_st) + e - b + 1);
|
||||||
|
if (unlikely(!srv)) {
|
||||||
|
fprintf(stderr, "%s: not enough memory\n", __FUNCTION__);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
srv_node = &srv->node;
|
srv_node = &srv->node;
|
||||||
memcpy(&srv_node->key, b, e - b);
|
memcpy(&srv_node->key, b, e - b);
|
||||||
srv_node->key[e - b] = '\0';
|
srv_node->key[e - b] = '\0';
|
||||||
@ -1680,6 +1684,10 @@ void filter_count_url(const char *accept_field, const char *time_field, struct t
|
|||||||
*/
|
*/
|
||||||
if (unlikely(!ustat))
|
if (unlikely(!ustat))
|
||||||
ustat = calloc(1, sizeof(*ustat));
|
ustat = calloc(1, sizeof(*ustat));
|
||||||
|
if (unlikely(!ustat)) {
|
||||||
|
fprintf(stderr, "%s: not enough memory\n", __FUNCTION__);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
ustat->nb_err = err;
|
ustat->nb_err = err;
|
||||||
ustat->nb_req = 1;
|
ustat->nb_req = 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user