]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: applet: Improve applet API to take care of inbuf/outbuf alloc failures
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 17 Jul 2025 13:08:55 +0000 (15:08 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 24 Jul 2025 07:16:56 +0000 (09:16 +0200)
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.

include/haproxy/applet.h

index 2b1a5af7f5fe9c38d929fd6e5b237aa20ad2cc65..6856a3b289ad61328e322b057a3c6b650cb9cd18 100644 (file)
@@ -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));
 }