From: Christopher Faulet Date: Thu, 17 Jul 2025 13:08:55 +0000 (+0200) Subject: MINOR: applet: Improve applet API to take care of inbuf/outbuf alloc failures X-Git-Tag: v3.3-dev4~28 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1f9a1cbefc164391642d8b42e597c14c39055c1e;p=thirdparty%2Fhaproxy.git MINOR: applet: Improve applet API to take care of inbuf/outbuf alloc failures applet_get_inbuf() and applet_get_outbuf() functions were not testing if the buffers were available. So, the caller had to check them before calling one of these functions. It is not really handy. So now, these functions take care to have a fully usable buffer before returning. Otherwise NULL is returned. --- diff --git a/include/haproxy/applet.h b/include/haproxy/applet.h index 2b1a5af7f..6856a3b28 100644 --- a/include/haproxy/applet.h +++ b/include/haproxy/applet.h @@ -288,8 +288,11 @@ static inline void applet_expect_data(struct appctx *appctx) */ static inline struct buffer *applet_get_inbuf(struct appctx *appctx) { - if (appctx->flags & APPCTX_FL_INOUT_BUFS) + if (appctx->flags & APPCTX_FL_INOUT_BUFS) { + if (applet_fl_test(appctx, APPCTX_FL_INBLK_ALLOC) || !appctx_get_buf(appctx, &appctx->inbuf)) + return NULL; return &appctx->inbuf; + } else return sc_ob(appctx_sc(appctx)); } @@ -300,8 +303,12 @@ static inline struct buffer *applet_get_inbuf(struct appctx *appctx) */ static inline struct buffer *applet_get_outbuf(struct appctx *appctx) { - if (appctx->flags & APPCTX_FL_INOUT_BUFS) + if (appctx->flags & APPCTX_FL_INOUT_BUFS) { + if (applet_fl_test(appctx, APPCTX_FL_OUTBLK_ALLOC|APPCTX_FL_OUTBLK_FULL) || + !appctx_get_buf(appctx, &appctx->outbuf)) + return NULL; return &appctx->outbuf; + } else return sc_ib(appctx_sc(appctx)); }