From: Christopher Faulet Date: Wed, 6 Sep 2023 06:33:57 +0000 (+0200) Subject: BUG/MEDIUM: applet: Fix API for function to push new data in channels buffer X-Git-Tag: v2.9-dev5~44 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3ec156f02706ec84198da1d7cb53ea638fe96980;p=thirdparty%2Fhaproxy.git BUG/MEDIUM: applet: Fix API for function to push new data in channels buffer All applets only check the -1 error value (need room) for applet_put* functions while the underlying functions may also return -2 if the input is closed or -3 if the data length is invalid. It means applets already handle other cases by their own. The API should be fixed but for now, to ease backports, we only fix applet_put* functions to always return -1 on error. This way, at least for the applets point of view, the API is consistent. This patch should be backported to 2.8. Probably not further. Except if we suspect it could fix a bug. --- diff --git a/include/haproxy/applet.h b/include/haproxy/applet.h index 62df5c833c..2e342f8900 100644 --- a/include/haproxy/applet.h +++ b/include/haproxy/applet.h @@ -177,8 +177,15 @@ static inline int applet_putchk(struct appctx *appctx, struct buffer *chunk) int ret; ret = ci_putchk(sc_ic(se->sc), chunk); - if (ret == -1) + if (ret < 0) { + /* XXX: Handle all errors as a lack of space because callers + * don't handles other cases for now. So applets must be + * carefull to handles shutdown (-2) and invalid calls (-3) by + * themselves. + */ sc_need_room(se->sc, chunk->data); + ret = -1; + } return ret; } @@ -193,8 +200,15 @@ static inline int applet_putblk(struct appctx *appctx, const char *blk, int len) int ret; ret = ci_putblk(sc_ic(se->sc), blk, len); - if (ret == -1) + if (ret < -1) { + /* XXX: Handle all errors as a lack of space because callers + * don't handles other cases for now. So applets must be + * carefull to handles shutdown (-2) and invalid calls (-3) by + * themselves. + */ sc_need_room(se->sc, len); + ret = -1; + } return ret; } @@ -210,8 +224,15 @@ static inline int applet_putstr(struct appctx *appctx, const char *str) int ret; ret = ci_putstr(sc_ic(se->sc), str); - if (ret == -1) + if (ret == -1) { + /* XXX: Handle all errors as a lack of space because callers + * don't handles other cases for now. So applets must be + * carefull to handles shutdown (-2) and invalid calls (-3) by + * themselves. + */ sc_need_room(se->sc, strlen(str)); + ret = -1; + } return ret; } @@ -226,8 +247,15 @@ static inline int applet_putchr(struct appctx *appctx, char chr) int ret; ret = ci_putchr(sc_ic(se->sc), chr); - if (ret == -1) + if (ret == -1) { + /* XXX: Handle all errors as a lack of space because callers + * don't handles other cases for now. So applets must be + * carefull to handles shutdown (-2) and invalid calls (-3) by + * themselves. + */ sc_need_room(se->sc, 1); + ret = -1; + } return ret; }