git: b8c1aadef9d8 - main - login_cap.c: Don't set errno to ERANGE on memory allocation failure
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 02 Oct 2023 20:46:27 UTC
The branch main has been updated by emaste:
URL: https://cgit.FreeBSD.org/src/commit/?id=b8c1aadef9d80786daf731300c33d3a001261422
commit b8c1aadef9d80786daf731300c33d3a001261422
Author: Olivier Certner <olce.freebsd@certner.fr>
AuthorDate: 2023-05-25 11:48:40 +0000
Commit: Ed Maste <emaste@FreeBSD.org>
CommitDate: 2023-10-02 20:41:22 +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
---
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;