From d3dd24add0ecd4b08d665337c37e10d31f18afec Mon Sep 17 00:00:00 2001 From: Tim Wickberg <tim@schedmd.com> Date: Mon, 24 Oct 2016 16:33:32 -0400 Subject: [PATCH] Prevent feeding strerror() a negative value. Many open Coverity issues point back to this. The results of passing a negative value to strerror() are undefined, return a static string instead. --- src/common/slurm_errno.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/common/slurm_errno.c b/src/common/slurm_errno.c index 99826e1bbea..9238d048f33 100644 --- a/src/common/slurm_errno.c +++ b/src/common/slurm_errno.c @@ -492,7 +492,12 @@ static char *_lookup_slurm_api_errtab(int errnum) char *slurm_strerror(int errnum) { char *res = _lookup_slurm_api_errtab(errnum); - return (res ? res : strerror(errnum)); + if (res) + return res; + else if (errnum > 0) + return strerror(errnum); + else + return "Unknown negative error number"; } /* -- GitLab