summaryrefslogtreecommitdiffstats
path: root/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'helpers')
-rw-r--r--helpers/mknod.c24
1 files changed, 23 insertions, 1 deletions
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);