Skip to content

eBPF-based security platform

upatch: print none for an empty list once the bpffs directory exists

Daniel Borkmann5d943fc5b923
diff --git a/builtin-upatch.c b/builtin-upatch.c
index dc1ac2dd..ba9f7aa8 100644
--- a/builtin-upatch.c
+++ b/builtin-upatch.c
@@ -475,6 +475,11 @@ static int is_upatch_file(const struct dirent *e)
return len > 7 && strcmp(e->d_name + len - 7, ".upatch") == 0;
}
+static int is_not_dot(const struct dirent *e)
+{
+ return strcmp(e->d_name, ".") && strcmp(e->d_name, "..");
+}
+
static bool upatch_is_loaded(const char *name)
{
char pin[PATH_MAX];
@@ -527,7 +532,7 @@ static int cmd_upatch_list(int argc, const char **argv)
alphasort);
if (np < 0)
np = 0;
- na = scandir(BPFFS_UPATCHES_DIR, &active, NULL, alphasort);
+ na = scandir(BPFFS_UPATCHES_DIR, &active, is_not_dot, alphasort);
if (na < 0)
na = 0;
@@ -602,8 +607,6 @@ static int cmd_upatch_list(int argc, const char **argv)
const char *nm = active[i]->d_name;
struct stat st;
- if (strcmp(nm, ".") == 0 || strcmp(nm, "..") == 0)
- continue;
if (upatch_name_from_bpffs(raw_name, sizeof(raw_name), nm))
continue;
if (strsprintf(persist, sizeof(persist), "%s/%s.upatch",
diff --git a/testing/functional/upatch/t3105-load-unload.sh b/testing/functional/upatch/t3105-load-unload.sh
index b17650f1..e28c8f2a 100644
--- a/testing/functional/upatch/t3105-load-unload.sh
+++ b/testing/functional/upatch/t3105-load-unload.sh
@@ -48,4 +48,10 @@ test_expect_success 'a correctly-bound UNLOAD directive detaches + removes the p
[ ! -e "$PIN" ]
'
+test_expect_success 'the list drops the upatch and never ends on a bare header' '
+ "$SHIRUDO_BIN" upatch list >"$WORK/list" 2>/dev/null &&
+ ! grep -q "$NAME" "$WORK/list" &&
+ ! tail -n 1 "$WORK/list" | grep -q "^ NAME "
+'
+
test_done