Skip to content

Commit

Permalink
getsockopt: move the options check to the upper layer
Browse files Browse the repository at this point in the history
check parameters at the top level to avoid errors when assigning
values in si_getsockopt.

Signed-off-by: zhanghongyu <[email protected]>
  • Loading branch information
zhhyu7 committed Feb 25, 2025
1 parent 425ddc7 commit 1886440
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions net/socket/getsockopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,6 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option,
{
FAR struct socket_conn_s *conn = psock->s_conn;

/* Verify that the socket option if valid (but might not be supported ) */

if (!value || !value_len)
{
return -EINVAL;
}

/* Process the options always handled locally */

switch (option)
Expand Down Expand Up @@ -271,6 +264,13 @@ int psock_getsockopt(FAR struct socket *psock, int level, int option,
{
int ret = -ENOPROTOOPT;

/* Verify that the socket option is valid (but might not be supported ) */

if (value == NULL || value_len == NULL || *value_len == 0)
{
return -EINVAL;
}

/* Verify that the sockfd corresponds to valid, allocated socket */

if (psock == NULL || psock->s_conn == NULL)
Expand Down

0 comments on commit 1886440

Please sign in to comment.