Skip to content

Commit a8584ba

Browse files
committed
avoid assertion when opening non existent /proc/net/(tcp|udp|raw)6 files
1 parent 7d22d85 commit a8584ba

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

userspace/libscap/scap_fds.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,10 +1153,16 @@ int32_t scap_fd_read_sockets(scap_t *handle, scap_fdinfo **sockets)
11531153
return SCAP_FAILURE;
11541154
}
11551155

1156-
scap_fd_read_ipv6_sockets_from_proc_fs(handle, "/proc/net/tcp6", SCAP_L4_TCP, sockets);
1157-
scap_fd_read_ipv6_sockets_from_proc_fs(handle, "/proc/net/udp6", SCAP_L4_UDP, sockets);
1158-
scap_fd_read_ipv6_sockets_from_proc_fs(handle, "/proc/net/raw6", SCAP_L4_RAW, sockets);
1159-
1156+
/* We assume if there is /proc/net/tcp6 that ipv6 is avaiable */
1157+
if(0 == access("/proc/net/tcp6", R_OK)) {
1158+
if(SCAP_FAILURE == scap_fd_read_ipv6_sockets_from_proc_fs(handle, "/proc/net/tcp6", SCAP_L4_TCP, sockets) ||
1159+
SCAP_FAILURE == scap_fd_read_ipv6_sockets_from_proc_fs(handle, "/proc/net/udp6", SCAP_L4_UDP, sockets) ||
1160+
SCAP_FAILURE == scap_fd_read_ipv6_sockets_from_proc_fs(handle, "/proc/net/raw6", SCAP_L4_RAW, sockets))
1161+
{
1162+
scap_fd_free_table(handle, sockets);
1163+
return SCAP_FAILURE;
1164+
}
1165+
}
11601166
return SCAP_SUCCESS;
11611167
}
11621168

0 commit comments

Comments
 (0)