summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-12-23 11:09:47 +0100
committerLennart Poettering <lennart@poettering.net>2017-02-07 11:22:05 +0100
commit2eedfd2d8b3441e8cf6dae4bdc9afaefbda19c39 (patch)
treef56a3995dab38701b8289840e4633d33ccd8a4f3 /src
parent20b7a0070c2f5a31442f59bece47f7f0875da3cd (diff)
dissect: make sure to manually follow symlinks when mounting dissected image
If the dissected image contains symlinks for the mount points we need we need to make sure to follow this with chase_symlinks() so that we don't leave the image.
Diffstat (limited to 'src')
-rw-r--r--src/shared/dissect-image.c39
1 files changed, 24 insertions, 15 deletions
diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c
index 878cb008aa..5fc2ce25f0 100644
--- a/src/shared/dissect-image.c
+++ b/src/shared/dissect-image.c
@@ -28,6 +28,7 @@
#include "blkid-util.h"
#include "dissect-image.h"
#include "fd-util.h"
+#include "fs-util.h"
#include "gpt.h"
#include "mount-util.h"
#include "path-util.h"
@@ -35,6 +36,7 @@
#include "stdio-util.h"
#include "string-table.h"
#include "string-util.h"
+#include "strv.h"
#include "udev-util.h"
static int probe_filesystem(const char *node, char **ret_fstype) {
@@ -624,7 +626,9 @@ static int mount_partition(
DissectImageFlags flags) {
const char *p, *options = NULL, *node, *fstype;
+ _cleanup_free_ char *chased = NULL;
bool rw;
+ int r;
assert(m);
assert(where);
@@ -641,9 +645,13 @@ static int mount_partition(
rw = m->rw && !(flags & DISSECT_IMAGE_READ_ONLY);
- if (directory)
- p = strjoina(where, directory);
- else
+ if (directory) {
+ r = chase_symlinks(directory, where, CHASE_PREFIX_ROOT, &chased);
+ if (r < 0)
+ return r;
+
+ p = chased;
+ } else
p = where;
/* If requested, turn on discard support. */
@@ -677,22 +685,23 @@ int dissected_image_mount(DissectedImage *m, const char *where, DissectImageFlag
return r;
if (m->partitions[PARTITION_ESP].found) {
- const char *mp, *x;
+ const char *mp;
/* Mount the ESP to /efi if it exists and is empty. If it doesn't exist, use /boot instead. */
- mp = "/efi";
- x = strjoina(where, mp);
- r = dir_is_empty(x);
- if (r == -ENOENT) {
- mp = "/boot";
- x = strjoina(where, mp);
- r = dir_is_empty(x);
- }
- if (r > 0) {
- r = mount_partition(m->partitions + PARTITION_ESP, where, mp, flags);
+ FOREACH_STRING(mp, "/efi", "/boot") {
+ _cleanup_free_ char *p = NULL;
+
+ r = chase_symlinks(mp, where, CHASE_PREFIX_ROOT, &p);
if (r < 0)
- return r;
+ continue;
+
+ r = dir_is_empty(p);
+ if (r > 0) {
+ r = mount_partition(m->partitions + PARTITION_ESP, where, mp, flags);
+ if (r < 0)
+ return r;
+ }
}
}