@@ -495,10 +495,10 @@ static int parse_mount_bind_options(const char *options, unsigned long *mount_fl
495495}
496496
497497static int mount_bind (const char * dest , CustomMount * m ) {
498- struct stat source_st , dest_st ;
499- const char * where ;
498+
499+ _cleanup_free_ char * mount_opts = NULL , * where = NULL ;
500500 unsigned long mount_flags = MS_BIND | MS_REC ;
501- _cleanup_free_ char * mount_opts = NULL ;
501+ struct stat source_st , dest_st ;
502502 int r ;
503503
504504 assert (m );
@@ -512,7 +512,9 @@ static int mount_bind(const char *dest, CustomMount *m) {
512512 if (stat (m -> source , & source_st ) < 0 )
513513 return log_error_errno (errno , "Failed to stat %s: %m" , m -> source );
514514
515- where = prefix_roota (dest , m -> destination );
515+ r = chase_symlinks_prefix (m -> destination , dest , & where );
516+ if (r < 0 )
517+ return log_error_errno (r , "Failed to resolve %s: %m" , m -> destination );
516518
517519 if (stat (where , & dest_st ) >= 0 ) {
518520 if (S_ISDIR (source_st .st_mode ) && !S_ISDIR (dest_st .st_mode )) {
@@ -563,14 +565,16 @@ static int mount_tmpfs(
563565 bool userns , uid_t uid_shift , uid_t uid_range ,
564566 const char * selinux_apifs_context ) {
565567
566- const char * where , * options ;
567- _cleanup_free_ char * buf = NULL ;
568+ const char * options ;
569+ _cleanup_free_ char * buf = NULL , * where = NULL ;
568570 int r ;
569571
570572 assert (dest );
571573 assert (m );
572574
573- where = prefix_roota (dest , m -> destination );
575+ r = chase_symlinks_prefix (m -> destination , dest , & where );
576+ if (r < 0 )
577+ return log_error_errno (r , "Failed to resolve %s: %m" , m -> destination );
574578
575579 r = mkdir_p_label (where , 0755 );
576580 if (r < 0 && r != - EEXIST )
@@ -600,14 +604,17 @@ static char *joined_and_escaped_lower_dirs(char * const *lower) {
600604}
601605
602606static int mount_overlay (const char * dest , CustomMount * m ) {
603- _cleanup_free_ char * lower = NULL ;
604- const char * where , * options ;
607+
608+ _cleanup_free_ char * lower = NULL , * where = NULL ;
609+ const char * options ;
605610 int r ;
606611
607612 assert (dest );
608613 assert (m );
609614
610- where = prefix_roota (dest , m -> destination );
615+ r = chase_symlinks_prefix (m -> destination , dest , & where );
616+ if (r < 0 )
617+ return log_error_errno (r , "Failed to resolve %s: %m" , m -> destination );
611618
612619 r = mkdir_label (where , 0755 );
613620 if (r < 0 && r != - EEXIST )
0 commit comments