patches: Bring back address structure length checks
Commit
560e66eee119 ("patches: Add patches for Musl compatibility")
added the `src/api: Make sockets.c compatible with Musl` patch to
fix the incompatibility issued build errors when building with Musl.
Precisely, Musl does not define the address length fields of socket
address structures: `sin_len`/`sa_len`. These structures were added
with 4.3BSD-Reno, however POSIX does not require this field and
therefore it is not standardized.
Unfortunately, the aforementioned patch also removes some important
address family length checks. For example, in the `accept()` syscall
case, the address length passed as application provided argument is
documented as meant to be overwritten by the kernel with the actual
length of the filled-in address structure and not be relied upon by
the kernel. A case where an application would pass a nonsense value
for this argument can be seen in the case of `perl 5.38`, whose
`strace` output contains the following:
```
accept4(3, {sa_family=AF_INET, sin_port=htons(45754), sin_addr=inet_addr("127.0.0.1")}, [4096 => 16], SOCK_CLOEXEC) = 4
```
where the size of the address structure is passed as `4096` and then
overwritten to `16`, the correct value.
In order to handle such cases properly, add back those checks.
Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Eduard Vintilă <eduard.vintila47@gmail.com>
Reviewed-by: Maria Pană <maria.pana4@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
GitHub-Closes: #56