* @brief Retrieves the value of a socket option. * * This system call retrieves the current value of a socket option for the specified socket. The socket * options allow fine-grained control over various aspects of socket behavior, such as timeouts, buffering, * and connection settings. The option value is stored in the `optval` buffer, and the size of the buffer * is specified by the `optlen
| 5390 | * Failing to provide a correctly sized buffer could result in undefined behavior or buffer overflows. |
| 5391 | */ |
| 5392 | sysret_t sys_getsockopt(int socket, int level, int optname, void *optval, socklen_t *optlen) |
| 5393 | { |
| 5394 | int ret = 0; |
| 5395 | socklen_t koptlen = 0; |
| 5396 | void *koptval = RT_NULL; |
| 5397 | |
| 5398 | if (!lwp_user_accessable((void *)optlen, sizeof(uint32_t))) |
| 5399 | return -EFAULT; |
| 5400 | |
| 5401 | if (lwp_get_from_user(&koptlen, optlen, sizeof(uint32_t)) != sizeof(uint32_t)) |
| 5402 | { |
| 5403 | return -EINVAL; |
| 5404 | } |
| 5405 | |
| 5406 | if (!lwp_user_accessable((void *)optval, koptlen)) |
| 5407 | return -EFAULT; |
| 5408 | |
| 5409 | koptval = kmem_get(koptlen); |
| 5410 | if (koptval == RT_NULL) |
| 5411 | { |
| 5412 | return -ENOMEM; |
| 5413 | } |
| 5414 | |
| 5415 | if (lwp_get_from_user(koptval, optval, koptlen) != koptlen) |
| 5416 | { |
| 5417 | kmem_put(koptval); |
| 5418 | return -EINVAL; |
| 5419 | } |
| 5420 | |
| 5421 | convert_sockopt(&level, &optname); |
| 5422 | ret = getsockopt(socket, level, optname, koptval, &koptlen); |
| 5423 | |
| 5424 | lwp_put_to_user((void *)optval, koptval, koptlen); |
| 5425 | lwp_put_to_user((void *)optlen, &koptlen, sizeof(uint32_t)); |
| 5426 | |
| 5427 | kmem_put(koptval); |
| 5428 | |
| 5429 | return (ret < 0 ? GET_ERRNO() : ret); |
| 5430 | } |
| 5431 | |
| 5432 | /** |
| 5433 | * @brief Sets the value of a socket option. |
nothing calls this directly
no test coverage detected