Skip to content

Commit

Permalink
libflux: handle flux_respond_error (errnum=0)
Browse files Browse the repository at this point in the history
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 flux-framework#3036
  • Loading branch information
garlick authored and mergify[bot] committed Jul 26, 2022
1 parent d1c1075 commit 2951896
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/common/libflux/response.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/common/libflux/response.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2951896

Please sign in to comment.