Skip to content

Commit

Permalink
Fix getgrnam_r error handling.
Browse files Browse the repository at this point in the history
Closes #884.
  • Loading branch information
ashinn committed May 31, 2024
1 parent 7885db9 commit 0bbb600
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/chibi/system.sld
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
(getpwuid_r user (make-string 1024)))))
(define (group-information group)
(safe-car (if (string? group)
(getgrnam_r group (make-string 1024))
(getgrgid_r group (make-string 1024)))))))))
(getgrnam-safe group (make-string 1024))
(getgrgid-safe group (make-string 1024)))))))))
39 changes: 30 additions & 9 deletions lib/chibi/system.stub
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,36 @@
(cond-expand
(emscripten)
(else
(define-c errno getgrgid_r
(gid_t (result group)
(c-declare "
int getgrnam_safe(const char* name, struct group* grp,
char* buf, size_t buflen,
struct group** result) {
int res = getgrnam_r(name, grp, buf, buflen, result);
if (res == 0 && result == NULL) {
res = errno ? errno : ENOENT;
}
return res;
}
int getgrgid_safe(gid_t gid, struct group* grp,
char* buf, size_t buflen,
struct group** result) {
int res = getgrgid_r(gid, grp, buf, buflen, result);
if (res == 0 && result == NULL) {
res = errno ? errno : ENOENT;
}
return res;
}
")

(define-c errno getgrgid-safe
(gid_t (result group)
(link string)
(value (string-size arg2) int)
(result pointer group)))

(define-c errno getgrnam-safe
(string (result group)
(link string)
(value (string-size arg2) int)
(result pointer group)))

(define-c errno getgrnam_r
(string (result group)
(link string)
(value (string-size arg2) int)
(result pointer group)))))
(result pointer group)))))

0 comments on commit 0bbb600

Please sign in to comment.