Skip to content

Commit fbd0fb2

Browse files
alexanderstephanGarfield96
authored andcommitted
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>
1 parent 8c555a4 commit fbd0fb2

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

admin/halog/halog.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,6 +1571,10 @@ void filter_count_srv_status(const char *accept_field, const char *time_field, s
15711571
if (!srv_node) {
15721572
/* server not yet in the tree, let's create it */
15731573
srv = (void *)calloc(1, sizeof(struct srv_st) + e - b + 1);
1574+
if (unlikely(!srv)) {
1575+
fprintf(stderr, "%s: not enough memory\n", __FUNCTION__);
1576+
exit(1);
1577+
}
15741578
srv_node = &srv->node;
15751579
memcpy(&srv_node->key, b, e - b);
15761580
srv_node->key[e - b] = '\0';
@@ -1680,6 +1684,10 @@ void filter_count_url(const char *accept_field, const char *time_field, struct t
16801684
*/
16811685
if (unlikely(!ustat))
16821686
ustat = calloc(1, sizeof(*ustat));
1687+
if (unlikely(!ustat)) {
1688+
fprintf(stderr, "%s: not enough memory\n", __FUNCTION__);
1689+
exit(1);
1690+
}
16831691

16841692
ustat->nb_err = err;
16851693
ustat->nb_req = 1;

0 commit comments

Comments
 (0)