ABSTRACT-LISTEN with option user calls fchown()

This commit is contained in:
Gerhard Rieger 2021-10-31 11:39:47 +01:00
parent ea5beb8e75
commit a390dfc547
3 changed files with 68 additions and 4 deletions

View file

@ -27,6 +27,14 @@ Corrections:
(for port) could not be resolved.
Test: BAD_SERVICE
Using options of NAMED group, e.g.chown, with abstract UNIX domain
sockets, produced errors because the function was applied with a normal
file system related call, e.g.chown(), using file "" (empty name). Instead of
chown(), Socat now uses fchown() on the file descriptor. However, such
a call usually has no real effect.
Test: ABSTRACT_USER
Thanks to Andreas Fink for reporting this issue.
Testing:
Prevent the TIMESTAMP tests from sporadically failing due do seconds
overflow

47
test.sh
View file

@ -15130,6 +15130,49 @@ PORT=$((PORT+1))
N=$((N+1))
# Test if the user option with abstract UNIX domain socket is not applied to
# file "" (empty name)
NAME=ABSTRACT_USER
case "$TESTS" in
*%$N%*|*%functions%*|*%bugs%*|*%socket%*|*%unix%*|*%abstract%*|*%$NAME%*)
TEST="$NAME: Is the fs related user option on ABSTRACT socket applied to FD"
# Apply the user option to an abstract socket; check if this produces an error.
# No error should occur
if ! eval $NUMCOND; then :;
elif [ "$UNAME" != Linux ]; then
$PRINTF "test $F_n $TEST... ${YELLOW}only on Linux${NORMAL}\n" $N
numCANT=$((numCANT+1))
listCANT="$listCANT $N"
else
tf="$td/test$N.stdout"
te="$td/test$N.stderr"
tdiff="$td/test$N.diff"
da="test$N $(date) $RANDOM"
CMD="$TRACE $SOCAT ABSTRACT-LISTEN:temp,accept-timeout=0.1,user=$USER FILE:/dev/null"
printf "test $F_n $TEST... " $N
$CMD >/dev/null 2>"${te}"
echo "$da" |$CMD >"${tf}1" 2>"${te}1"
rc=$?
if [ $rc -eq 0 ]; then
$PRINTF "$OK\n"
if [ "$VERBOSE" ]; then
echo "$CMD" >&2
fi
numOK=$((numOK+1))
else
$PRINTF "$FAILED\n"
echo "$CMD" >&2
cat "${te}" >&2
numFAIL=$((numFAIL+1))
listFAIL="$listFAIL $N"
fi
fi # NUMCOND
;;
esac
PORT=$((PORT+1))
N=$((N+1))
# end of common tests
##################################################################################
@ -15253,7 +15296,11 @@ rc1=$?
kill $pid0 2>/dev/null; wait
if [ !!! ]; then
$PRINTF "$OK\n"
<<<<<<< HEAD
if [" $VERBOSE" ]; then
=======
if [ "$VERBOSE" ]; then
>>>>>>> 8e56329... ABSTEACT-LISTEN with option user calls fchown()
echo "$CMD0 &" >&2
echo "$CMD1" >&2
fi

View file

@ -164,7 +164,11 @@ int _xioopen_listen(struct single *xfd, int xioflags, struct sockaddr *us, sockl
#if WITH_UNIX
if (us->sa_family == AF_UNIX) {
applyopts_named(((struct sockaddr_un *)us)->sun_path, opts, PH_FD);
if (((union sockaddr_union *)us)->un.sun_path[0] != '\0') {
applyopts_named(((struct sockaddr_un *)us)->sun_path, opts, PH_FD);
} else {
applyopts(xfd->fd, opts, PH_FD);
}
}
#endif
/* under some circumstances (e.g., TCP listen on port 0) bind() fills empty
@ -178,9 +182,14 @@ int _xioopen_listen(struct single *xfd, int xioflags, struct sockaddr *us, sockl
applyopts(xfd->fd, opts, PH_PASTBIND);
#if WITH_UNIX
if (us->sa_family == AF_UNIX) {
/*applyopts_early(((struct sockaddr_un *)us)->sun_path, opts);*/
applyopts_named(((struct sockaddr_un *)us)->sun_path, opts, PH_EARLY);
applyopts_named(((struct sockaddr_un *)us)->sun_path, opts, PH_PREOPEN);
if (((union sockaddr_union *)us)->un.sun_path[0] != '\0') {
/*applyopts_early(((struct sockaddr_un *)us)->sun_path, opts);*/
applyopts_named(((struct sockaddr_un *)us)->sun_path, opts, PH_EARLY);
applyopts_named(((struct sockaddr_un *)us)->sun_path, opts, PH_PREOPEN);
} else {
applyopts(xfd->fd, opts, PH_EARLY);
applyopts(xfd->fd, opts, PH_PREOPEN);
}
}
#endif /* WITH_UNIX */