summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2023-07-05 17:51:43 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2023-07-05 17:52:25 (EDT)
commit6bd5bd386a4612661d3b224bf27cad7e9b4032bb (patch)
tree14bd8c91d2ec4fbe440387a19daea98251b30876
parentb02e24a1e51e34f4bccb9094fbaa6801802b12ac (diff)
mknod: Find path relative to pkg data dir
All tests now pass.
-rw-r--r--configure.ac4
-rw-r--r--helpers/mknod.c24
2 files changed, 25 insertions, 3 deletions
diff --git a/configure.ac b/configure.ac
index 76c6a07..c7dbab8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -47,8 +47,8 @@ AC_CHECK_FUNCS(
fread free fscanf fseek fstat fwrite getgrgid getpwuid \
localtime lstat malloc memcmp memcpy memset mkdir mkfifo open \
printf puts readlink scandir sleep snprintf sprintf stat \
- strchr strcmp strcpy strerror strftime strlen strncpy strtol \
- unlink vfprintf
+ strchr strcmp strcpy strerror strftime strlen strncmp strncpy \
+ strtol unlink vfprintf
],
[],
[funcs_missing=true])
diff --git a/helpers/mknod.c b/helpers/mknod.c
index 9e40080..9504b09 100644
--- a/helpers/mknod.c
+++ b/helpers/mknod.c
@@ -142,6 +142,7 @@ main(int argc, char *argv[])
char type;
long int major;
long int minor;
+ size_t work_area_len;
size_t specials_file_name_len;
char *specials_file_name;
char *specials_lock_name;
@@ -229,6 +230,27 @@ main(int argc, char *argv[])
return EXIT_FAILURE;
}
+ /* Find path of file relative to binary package data directory within
+ * build work area. */
+ work_area_len = strlen(work_area);
+ if (work_area[work_area_len - 1] == '/') {
+ --work_area_len;
+ }
+ if (strncmp(name, work_area, work_area_len) != 0 ||
+ name[work_area_len] != '/') {
+ _err(_("Node \"%s\" not within work area \"%s\""),
+ name, work_area);
+ return EXIT_FAILURE;
+ }
+ do {
+ ++work_area_len;
+ if (name[work_area_len] == '\0') {
+ _err(_("Node \"%s\" not within a binary package data "
+ "directory"), name);
+ return EXIT_FAILURE;
+ }
+ } while (name[work_area_len] != '/');
+
specials_file_name_len = strlen(work_area) + strlen("/specials") + 1;
specials_file_name = malloc(specials_file_name_len * 2 + 1);
if (specials_file_name == NULL) {
@@ -297,7 +319,7 @@ main(int argc, char *argv[])
}
if (fprintf(specials_file, "%c %8ld %8ld %s\n",
- type, major, minor, name) < 0) {
+ type, major, minor, name + work_area_len) < 0) {
_errno(_("Failed to write specials file"));
fclose(specials_file);
unlink(specials_lock_name);