* @brief Retrieves the local address of the socket. * * This system call retrieves the local address (local endpoint) that is bound to the specified socket. * The socket must be created and, if necessary, bound to a local address using `sys_bind`. The address * of the local endpoint is stored in the `name` structure, and the size of the structure is updated in `namelen`. * * @param[in] sock
| 5319 | * Failing to provide a correctly sized `namelen` could result in buffer overflows or undefined behavior. |
| 5320 | */ |
| 5321 | sysret_t sys_getsockname(int socket, struct musl_sockaddr *name, socklen_t *namelen) |
| 5322 | { |
| 5323 | int ret = -1; |
| 5324 | struct sockaddr sa; |
| 5325 | struct musl_sockaddr kname; |
| 5326 | socklen_t unamelen; |
| 5327 | socklen_t knamelen; |
| 5328 | |
| 5329 | if (!lwp_user_accessable(namelen, sizeof (socklen_t))) |
| 5330 | { |
| 5331 | return -EFAULT; |
| 5332 | } |
| 5333 | lwp_get_from_user(&unamelen, namelen, sizeof (socklen_t)); |
| 5334 | if (!unamelen) |
| 5335 | { |
| 5336 | return -EINVAL; |
| 5337 | } |
| 5338 | |
| 5339 | if (!lwp_user_accessable(name, unamelen)) |
| 5340 | { |
| 5341 | return -EFAULT; |
| 5342 | } |
| 5343 | |
| 5344 | knamelen = sizeof(struct sockaddr); |
| 5345 | ret = getsockname(socket, &sa, &knamelen); |
| 5346 | if (ret == 0) |
| 5347 | { |
| 5348 | sockaddr_tomusl(&sa, &kname); |
| 5349 | if (unamelen > sizeof(struct musl_sockaddr)) |
| 5350 | { |
| 5351 | unamelen = sizeof(struct musl_sockaddr); |
| 5352 | } |
| 5353 | lwp_put_to_user(name, &kname, unamelen); |
| 5354 | lwp_put_to_user(namelen, &unamelen, sizeof(socklen_t)); |
| 5355 | } |
| 5356 | else |
| 5357 | { |
| 5358 | ret = GET_ERRNO(); |
| 5359 | } |
| 5360 | return ret; |
| 5361 | } |
| 5362 | |
| 5363 | /** |
| 5364 | * @brief Retrieves the value of a socket option. |
nothing calls this directly
no test coverage detected