Add an early guard in ncbmb_make() to handle allocation failure paths
cleanly when area is NULL.

Returning NCBMBUF_NULL avoids dereferencing a null pointer in the
subsequent buffer/bitmap setup and memset, and fixes the related static
analysis warning (nullPointerOutOfMemory).

found by cppcheck:
cppcheck --enable=all -j$(nproc) -I include -I /usr/include 
--output-file=haproxy.log .
---
 src/ncbmbuf.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/ncbmbuf.c b/src/ncbmbuf.c
index e642e3d21..1e5c0993e 100644
--- a/src/ncbmbuf.c
+++ b/src/ncbmbuf.c
@@ -181,6 +181,9 @@ struct ncbmbuf ncbmb_make(char *area, ncb_sz_t size, 
ncb_sz_t head)
        struct ncbmbuf buf;
        ncb_sz_t size_bm;
 
+       if (!area)
+               return NCBMBUF_NULL;
+
        size_bm = (size + 8) / 9;
 
        buf.area = area;
-- 
2.46.0.windows.1



Reply via email to