Skip to content

Commit

Permalink
cat: persistent errno
Browse files Browse the repository at this point in the history
There is no guarantee that after close(2)/free the errno will remain
persistent. The caller of the udom_open function depends on the errno
for reporting errors.

Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D28185
  • Loading branch information
oshogbo committed Jan 16, 2021
1 parent 8ca9ff4 commit 6e8062c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion bin/cat/cat.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ udom_open(const char *path, int flags)
struct addrinfo hints, *res, *res0;
char rpath[PATH_MAX];
int fd = -1;
int error;
int error, serrno;
cap_rights_t rights;

/*
Expand All @@ -453,18 +453,23 @@ udom_open(const char *path, int flags)
fd = socket(res->ai_family, res->ai_socktype,
res->ai_protocol);
if (fd < 0) {
serrno = errno;
freeaddrinfo(res0);
errno = serrno;
return (-1);
}
if (caph_rights_limit(fd, &rights) < 0) {
serrno = errno;
close(fd);
freeaddrinfo(res0);
errno = serrno;
return (-1);
}
error = cap_connect(capnet, fd, res->ai_addr, res->ai_addrlen);
if (error == 0)
break;
else {
serrno = errno;
close(fd);
fd = -1;
}
Expand Down Expand Up @@ -492,9 +497,13 @@ udom_open(const char *path, int flags)

cap_rights_clear(&rights, CAP_CONNECT, CAP_SHUTDOWN);
if (caph_rights_limit(fd, &rights) < 0) {
serrno = errno;
close(fd);
errno = serrno;
return (-1);
}
} else {
errno = serrno;
}
return (fd);
}
Expand Down

0 comments on commit 6e8062c

Please sign in to comment.