From fc2463ce0ef1d7fcbdfed50105e006c3f2d28763 Mon Sep 17 00:00:00 2001 From: Jim Garlick Date: Mon, 25 Jul 2022 15:33:30 -0700 Subject: [PATCH] libflux: handle flux_respond_error (errnum=0) Problem: if flux_respond_error() is called with errnum of 0, no response is sent, which can cause hard to diagnose problems. Use EINVAL if errnum is zero. Fixes #3036 --- src/common/libflux/response.c | 4 +++- src/common/libflux/response.h | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/common/libflux/response.c b/src/common/libflux/response.c index a265d17844ef..08723f2bd546 100644 --- a/src/common/libflux/response.c +++ b/src/common/libflux/response.c @@ -315,8 +315,10 @@ int flux_respond_error (flux_t *h, const flux_msg_t *request, { flux_msg_t *msg = NULL; - if (!h || !request || errnum == 0) + if (!h || !request) goto inval; + if (errnum == 0) + errnum = EINVAL; if (flux_msg_is_noresponse (request)) return 0; msg = flux_response_derive (request, errnum); diff --git a/src/common/libflux/response.h b/src/common/libflux/response.h index 781a4e2edfb2..101f05c1ebf5 100644 --- a/src/common/libflux/response.h +++ b/src/common/libflux/response.h @@ -86,7 +86,8 @@ int flux_respond_raw (flux_t *h, const flux_msg_t *request, const void *data, int len); /* Create an error response to the provided request message with optional - * error string payload (if errstr is non-NULL). + * error string payload (if errstr is non-NULL). If errnum is zero, EINVAL + * is substituted. */ int flux_respond_error (flux_t *h, const flux_msg_t *request, int errnum, const char *errstr);