aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2022-07-05 12:16:36 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2022-07-08 19:17:35 +0200
commit75063b2e14dacc13fcbeeba24e580198a7c1c638 (patch)
treef58b8c85ed5472523a5596be3434f7488dbfe465 /bin
parent3946cf086183f8dd4d5d115f52ba1b87560b7ce4 (diff)
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 <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'bin')
-rw-r--r--bin/rdsquashfs/describe.c8
-rw-r--r--bin/rdsquashfs/fill_files.c7
-rw-r--r--bin/rdsquashfs/rdsquashfs.c4
-rw-r--r--bin/rdsquashfs/restore_fstree.c15
-rw-r--r--bin/sqfs2tar/write_tree.c6
-rw-r--r--bin/sqfsdiff/node_compare.c7
-rw-r--r--bin/sqfsdiff/util.c8
7 files changed, 31 insertions, 24 deletions
diff --git a/bin/rdsquashfs/describe.c b/bin/rdsquashfs/describe.c
index 1e723bc..540b126 100644
--- a/bin/rdsquashfs/describe.c
+++ b/bin/rdsquashfs/describe.c
@@ -8,10 +8,12 @@
static int print_name(const sqfs_tree_node_t *n, bool dont_escape)
{
- char *start, *ptr, *name = sqfs_tree_node_get_path(n);
+ char *start, *ptr, *name;
+ int ret;
- if (name == NULL) {
- perror("Recovering file path of tree node");
+ ret = sqfs_tree_node_get_path(n, &name);
+ if (ret != 0) {
+ sqfs_perror(NULL, "Recovering file path of tree node", ret);
return -1;
}
diff --git a/bin/rdsquashfs/fill_files.c b/bin/rdsquashfs/fill_files.c
index 8459c1e..923bc12 100644
--- a/bin/rdsquashfs/fill_files.c
+++ b/bin/rdsquashfs/fill_files.c
@@ -67,6 +67,7 @@ static int add_file(const sqfs_tree_node_t *node)
struct file_ent *new;
size_t new_sz;
char *path;
+ int ret;
if (num_files == max_files) {
new_sz = max_files ? max_files * 2 : 256;
@@ -81,9 +82,9 @@ static int add_file(const sqfs_tree_node_t *node)
max_files = new_sz;
}
- path = sqfs_tree_node_get_path(node);
- if (path == NULL) {
- perror("assembling file path");
+ ret = sqfs_tree_node_get_path(node, &path);
+ if (ret != 0) {
+ sqfs_perror(NULL, "assembling file path", ret);
return -1;
}
diff --git a/bin/rdsquashfs/rdsquashfs.c b/bin/rdsquashfs/rdsquashfs.c
index a8dc4c9..8926df6 100644
--- a/bin/rdsquashfs/rdsquashfs.c
+++ b/bin/rdsquashfs/rdsquashfs.c
@@ -71,7 +71,9 @@ static int tree_sort(sqfs_tree_node_t *root)
for (it = root->children; it->next != NULL; it = it->next) {
if (strcmp((const char *)it->name,
(const char *)it->next->name) == 0) {
- char *path = sqfs_tree_node_get_path(it);
+ char *path;
+
+ sqfs_tree_node_get_path(it, &path);
fprintf(stderr, "Entry '%s' found more than once!\n",
path);
diff --git a/bin/rdsquashfs/restore_fstree.c b/bin/rdsquashfs/restore_fstree.c
index cf5bc2a..b9f92fe 100644
--- a/bin/rdsquashfs/restore_fstree.c
+++ b/bin/rdsquashfs/restore_fstree.c
@@ -127,10 +127,10 @@ static int create_node_dfs(const sqfs_tree_node_t *n, int flags)
return 0;
}
- name = sqfs_tree_node_get_path(n);
- if (name == NULL) {
- fprintf(stderr, "Constructing full path for '%s': %s\n",
- (const char *)n->name, strerror(errno));
+ ret = sqfs_tree_node_get_path(n, &name);
+ if (ret != 0) {
+ sqfs_perror((const char *)n->name,
+ "constructing full path", ret);
return -1;
}
@@ -226,10 +226,9 @@ static int set_attribs(sqfs_xattr_reader_t *xattr,
}
}
- path = sqfs_tree_node_get_path(n);
- if (path == NULL) {
- fprintf(stderr, "Reconstructing full path: %s\n",
- strerror(errno));
+ ret = sqfs_tree_node_get_path(n, &path);
+ if (ret != 0) {
+ sqfs_perror(NULL, "reconstructing full path", ret);
return -1;
}
diff --git a/bin/sqfs2tar/write_tree.c b/bin/sqfs2tar/write_tree.c
index d4f8366..1c19a5a 100644
--- a/bin/sqfs2tar/write_tree.c
+++ b/bin/sqfs2tar/write_tree.c
@@ -102,9 +102,9 @@ static int write_tree_dfs(const sqfs_tree_node_t *n)
return 0;
}
- name = sqfs_tree_node_get_path(n);
- if (name == NULL) {
- perror("resolving tree node path");
+ ret = sqfs_tree_node_get_path(n, &name);
+ if (ret != 0) {
+ sqfs_perror(NULL, "resolving tree node path", ret);
return -1;
}
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;
}