git: 83bcaf3b2d6c - stable/14 - login_cap.c: Don't set errno to ERANGE on memory allocation failure
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 13 Oct 2023 15:44:25 UTC
The branch stable/14 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=83bcaf3b2d6cb173ee126f504478fa6ace4f406f commit 83bcaf3b2d6cb173ee126f504478fa6ace4f406f Author: Olivier Certner <olce.freebsd@certner.fr> AuthorDate: 2023-05-25 11:48:40 +0000 Commit: Ed Maste <emaste@FreeBSD.org> CommitDate: 2023-10-13 14:13:38 +0000 login_cap.c: Don't set errno to ERANGE on memory allocation failure Modified functions: login_getcaptime(), login_getcapnum(), login_getcapsize(). They all call cgetstr(), which returns -2 on such conditions and already sets errno to ENOMEM, arguably the appropriate value for these functions as well. No in-tree consumer currently checks for errno on error reported by these functions, so this change has no other code impact. Reviewed by: kib MFC after: 2 weeks Sponsored by: Kumacom SAS Differential Revision: https://reviews.freebsd.org/D40342 (cherry picked from commit b8c1aadef9d80786daf731300c33d3a001261422) --- lib/libutil/login_cap.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/lib/libutil/login_cap.c b/lib/libutil/login_cap.c index e71d38d2d93b..aeda7d5e828b 100644 --- a/lib/libutil/login_cap.c +++ b/lib/libutil/login_cap.c @@ -650,10 +650,8 @@ login_getcaptime(login_cap_t *lc, const char *cap, rlim_t def, rlim_t error) if ((r = cgetstr(lc->lc_cap, cap, &res)) == -1) return def; - else if (r < 0) { - errno = ERANGE; + else if (r < 0) return error; - } /* "inf" and "infinity" are special cases */ if (isinfinite(res)) @@ -735,19 +733,18 @@ login_getcapnum(login_cap_t *lc, const char *cap, rlim_t def, rlim_t error) /* * For BSDI compatibility, try for the tag=<val> first */ - if ((r = cgetstr(lc->lc_cap, cap, &res)) == -1) { + r = cgetstr(lc->lc_cap, cap, &res); + if (r == -1) { long lval; /* string capability not present, so try for tag#<val> as numeric */ if ((r = cgetnum(lc->lc_cap, cap, &lval)) == -1) return def; /* Not there, so return default */ - else if (r >= 0) + else if (r < 0) + return error; + else return (rlim_t)lval; - } - - if (r < 0) { - errno = ERANGE; + } else if (r < 0) return error; - } if (isinfinite(res)) return RLIM_INFINITY; @@ -786,10 +783,8 @@ login_getcapsize(login_cap_t *lc, const char *cap, rlim_t def, rlim_t error) if ((r = cgetstr(lc->lc_cap, cap, &res)) == -1) return def; - else if (r < 0) { - errno = ERANGE; + else if (r < 0) return error; - } if (isinfinite(res)) return RLIM_INFINITY;