From 75063b2e14dacc13fcbeeba24e580198a7c1c638 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Tue, 5 Jul 2022 12:16:36 +0200 Subject: Make sqfs_tree_node_get_path more robust Test against various invariants: - Every non-root node must have a name - The root node muts not have a name - The name must not be ".." or "." - The name must not contain '/' - The loop that chases parent pointers must terminate, i.e. we must never reach the starting state again (link loop). Furthermore, make sure the sum of all path components plus separators does not overflow. Signed-off-by: David Oberhollenzer --- bin/sqfsdiff/node_compare.c | 7 ++++--- bin/sqfsdiff/util.c | 8 +++++--- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'bin/sqfsdiff') diff --git a/bin/sqfsdiff/node_compare.c b/bin/sqfsdiff/node_compare.c index 6e8c2fa..a0c99c7 100644 --- a/bin/sqfsdiff/node_compare.c +++ b/bin/sqfsdiff/node_compare.c @@ -8,13 +8,14 @@ int node_compare(sqfsdiff_t *sd, sqfs_tree_node_t *a, sqfs_tree_node_t *b) { - char *path = sqfs_tree_node_get_path(a); sqfs_tree_node_t *ait, *bit; bool promoted, demoted; int ret, status = 0; + char *path; - if (path == NULL) { - perror("constructing absolute file path"); + ret = sqfs_tree_node_get_path(a, &path); + if (ret != 0) { + sqfs_perror(NULL, "constructing absolute file path", ret); return -1; } diff --git a/bin/sqfsdiff/util.c b/bin/sqfsdiff/util.c index ab6fa59..a11770f 100644 --- a/bin/sqfsdiff/util.c +++ b/bin/sqfsdiff/util.c @@ -8,10 +8,12 @@ char *node_path(const sqfs_tree_node_t *n) { - char *path = sqfs_tree_node_get_path(n); + char *path; + int ret; - if (path == NULL) { - perror("get path"); + ret = sqfs_tree_node_get_path(n, &path); + if (ret != 0) { + sqfs_perror(NULL, "get path", ret); return NULL; } -- cgit v1.2.3