diff options
author | Gleb Smirnoff <glebius@FreeBSD.org> | 2024-04-25 04:50:58 +0000 |
---|---|---|
committer | Gleb Smirnoff <glebius@FreeBSD.org> | 2024-04-25 04:55:58 +0000 |
commit | 19307b86d31b7dea4bb5c3f7e233ee0e59049258 (patch) | |
tree | 847c0e2223fb1ac8cb05dde7406ab319736fa5c3 /sys/kern/uipc_accf.c | |
parent | c68eed82a3dcadf0c826e9e150f59769f4c44f24 (diff) | |
download | src-19307b86d31b7dea4bb5c3f7e233ee0e59049258.tar.gz src-19307b86d31b7dea4bb5c3f7e233ee0e59049258.zip |
accept_filter: return different errors for non-listener and a busy socket
The fact that an accept filter needs to be cleared first before setting to
a different one isn't properly documented. The requirement that the
socket needs already be listening, although trivial, isn't documented
either. At least return a more meaningful error than EINVAL for an
existing filter. Cover this with a test case.
Diffstat (limited to 'sys/kern/uipc_accf.c')
-rw-r--r-- | sys/kern/uipc_accf.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/sys/kern/uipc_accf.c b/sys/kern/uipc_accf.c index c63b5a1179bc..9e30e7839103 100644 --- a/sys/kern/uipc_accf.c +++ b/sys/kern/uipc_accf.c @@ -276,10 +276,14 @@ accept_filt_setopt(struct socket *so, struct sockopt *sopt) * without first removing it. */ SOCK_LOCK(so); - if (!SOLISTENING(so) || so->sol_accept_filter != NULL) { + if (__predict_false(!SOLISTENING(so))) { error = EINVAL; goto out; } + if (__predict_false(so->sol_accept_filter != NULL)) { + error = EBUSY; + goto out; + } /* * Invoke the accf_create() method of the filter if required. The |