mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-31 14:25:52 +00:00
tests: Fix socket addr lengths in unix_socket/unix_socket_client
Instead of using the entire sun_path buffer for abstract socket names, only use the exact length of the string that is specified on the command line. The nul-terminator is not included for abstract sockets. The size of sun_path is modified to include the nul-terminator for pathname address types. Signed-off-by: Tyler Hicks <tyhicks@canonical.com> Acked-by: Steve Beattie <steve@nxnw.org>
This commit is contained in:
@@ -107,11 +107,20 @@ int main (int argc, char *argv[])
|
||||
sun_path = argv[1];
|
||||
sun_path_len = strlen(sun_path);
|
||||
if (sun_path[0] == '@') {
|
||||
if (sun_path_len > sizeof(addr.sun_path)) {
|
||||
fprintf(stderr, "FAIL - socket addr too big\n");
|
||||
exit(1);
|
||||
}
|
||||
memcpy(addr.sun_path, sun_path, sun_path_len);
|
||||
addr.sun_path[0] = '\0';
|
||||
sun_path_len = sizeof(addr.sun_path);
|
||||
} else {
|
||||
memcpy(addr.sun_path, sun_path, sun_path_len + 1);
|
||||
/* include the nul terminator for pathname addr types */
|
||||
sun_path_len++;
|
||||
if (sun_path_len > sizeof(addr.sun_path)) {
|
||||
fprintf(stderr, "FAIL - socket addr too big\n");
|
||||
exit(1);
|
||||
}
|
||||
memcpy(addr.sun_path, sun_path, sun_path_len);
|
||||
}
|
||||
|
||||
if (!strcmp(argv[2], "stream")) {
|
||||
|
@@ -98,11 +98,20 @@ int main(int argc, char *argv[])
|
||||
sun_path = argv[1];
|
||||
sun_path_len = strlen(sun_path);
|
||||
if (sun_path[0] == '@') {
|
||||
if (sun_path_len > sizeof(peer_addr.sun_path)) {
|
||||
fprintf(stderr, "FAIL CLIENT - socket addr too big\n");
|
||||
exit(1);
|
||||
}
|
||||
memcpy(peer_addr.sun_path, sun_path, sun_path_len);
|
||||
peer_addr.sun_path[0] = '\0';
|
||||
sun_path_len = sizeof(peer_addr.sun_path);
|
||||
} else {
|
||||
memcpy(peer_addr.sun_path, sun_path, sun_path_len + 1);
|
||||
/* include the nul terminator for pathname addr types */
|
||||
sun_path_len++;
|
||||
if (sun_path_len > sizeof(peer_addr.sun_path)) {
|
||||
fprintf(stderr, "FAIL CLIENT - socket addr too big\n");
|
||||
exit(1);
|
||||
}
|
||||
memcpy(peer_addr.sun_path, sun_path, sun_path_len);
|
||||
}
|
||||
|
||||
if (!strcmp(argv[2], "stream")) {
|
||||
|
Reference in New Issue
Block a user