Skip to contentSkip to conversation

get_maintainer.pl: unexpected behaviour for path/to//file

PATCH Applied Emil Velikov 2 participants 5 messages May 15, 2020 – May 17, 2020 GET_MAINTAINER script

lore
Share & tools
lore
#0 lore raw

Hi Joe,

Recently I've noticed that get_maintainer behaves differently if there is a double, sequential, forward slash in the path.

AFAICT there should be no distinction between the two. Or at least many existing applications and scripts consider them one and the same.

I've tried fixing this, although my perl isn't quite up-to scratch. Is this some weird bug or some intended feature?

Thanks
Emil

Example:

./scripts/get_maintainer -F drivers/gpu/drm//lima

David Airlie <[email protected]> (maintainer:DRM DRIVERS)
Daniel Vetter <[email protected]> (maintainer:DRM DRIVERS,commit_signer:3/42=7%) Qiang Yu <[email protected]> (commit_signer:36/42=86%,authored:24/42=57%) Vasily Khoruzhick <[email protected]> (commit_signer:26/42=62%) Krzysztof Kozlowski <[email protected]> (commit_signer:5/42=12%,authored:5/42=12%) Emil Velikov <[email protected]> (commit_signer:4/42=10%) [email protected] (open list:DRM DRIVERS) [email protected] (open list)

./scripts/get_maintainer -F drivers/gpu/drm/lima

Qiang Yu <[email protected]> (maintainer:DRM DRIVERS FOR LIMA) David Airlie <[email protected]> (maintainer:DRM DRIVERS) Daniel Vetter <[email protected]> (maintainer:DRM DRIVERS) [email protected] (open list:DRM DRIVERS FOR LIMA) [email protected] (moderated list:DRM DRIVERS FOR LIMA) [email protected] (open list)

maintainer
#1 lore raw
Quoted 10 lines · Emil Velikov

Hi Joe,

Recently I've noticed that get_maintainer behaves differently if there is a double, sequential, forward slash in the path.

AFAICT there should be no distinction between the two. Or at least many existing applications and scripts consider them one and the same.

I've tried fixing this, although my perl isn't quite up-to scratch. Is this some weird bug or some intended feature?

Not really an intended feature.
The code counts slashes for directory depth.

I suppose it might be simpler to do this:

---
 scripts/get_maintainer.pl | 1 +
 1 file changed, 1 insertion(+)
scripts/get_maintainer.pl +1 -0
index 6d973f3685f9..eaaf9373dbcf 100755
@@ -538,6 +538,7 @@ foreach my $file (@ARGV) {
 	} elsif (!(-f $file)) {
 	    die "$P: file '${file}' not found\n";
 	}
+	$file =~ s@//@/@g;	# compress file double slashes
     }
     if ($from_filename || ($file ne "&STDIN" && vcs_file_exists($file))) {
 	$file =~ s/^\Q${cur_path}\E//;	#strip any absolute path
maintainer
#2 lore raw
Quoted 9 lines · Joe Perches
Quoted 8 lines · Emil Velikov

Hi Joe,

Recently I've noticed that get_maintainer behaves differently if there is a double, sequential, forward slash in the path.

AFAICT there should be no distinction between the two. Or at least many existing applications and scripts consider them one and the same.

Quoted 7 lines
Quoted 2 lines

I've tried fixing this, although my perl isn't quite up-to scratch. Is this some weird bug or some intended feature?

Not really an intended feature.
The code counts slashes for directory depth.

I suppose it might be simpler to do this:

Or perhaps a better alternative is:

---
 scripts/get_maintainer.pl | 2 ++
 1 file changed, 2 insertions(+)
scripts/get_maintainer.pl +2 -0
index 6d973f3685f9..484d2fbf5921 100755
@@ -19,6 +19,7 @@ my $V = '0.26';
 use Getopt::Long qw(:config no_auto_abbrev);
 use Cwd;
 use File::Find;
+use File::Spec::Functions;
 
 my $cur_path = fastgetcwd() . '/';
 my $lk_path = "./";
@@ -532,6 +533,7 @@ if (!@ARGV) {
 
 foreach my $file (@ARGV) {
     if ($file ne "&STDIN") {
+	$file = canonpath($file);
 	##if $file is a directory and it lacks a trailing slash, add one
 	if ((-d $file)) {
 	    $file =~ s@([^/])$@$1/@;
#3 lore raw
Quoted 37 lines · Joe Perches
Quoted 9 lines · Joe Perches
Quoted 8 lines · Emil Velikov

Hi Joe,

Recently I've noticed that get_maintainer behaves differently if there is a double, sequential, forward slash in the path.

AFAICT there should be no distinction between the two. Or at least many existing applications and scripts consider them one and the same.

Quoted 7 lines
Quoted 2 lines

I've tried fixing this, although my perl isn't quite up-to scratch. Is this some weird bug or some intended feature?

Not really an intended feature.
The code counts slashes for directory depth.

I suppose it might be simpler to do this:

Or perhaps a better alternative is:

---
 scripts/get_maintainer.pl | 2 ++
 1 file changed, 2 insertions(+)
scripts/get_maintainer.pl +1 -0
index 6d973f3685f9..484d2fbf5921 100755
@@ -19,6 +19,7 @@ my $V = '0.26';
 use Getopt::Long qw(:config no_auto_abbrev);
 use Cwd;
 use File::Find;
+use File::Spec::Functions;
 
 my $cur_path = fastgetcwd() . '/';
 my $lk_path = "./";

scripts/get_maintainer.pl if (!@ARGV) { · line 536

Quoted 4 lines
scripts/get_maintainer.pl +1 -0
@@ -532,6 +533,7 @@ if (!@ARGV) {
 
 foreach my $file (@ARGV) {
     if ($file ne "&STDIN") {
+       $file = canonpath($file);

This seems like the better option since it also handles path traversal. I would expect that people don't use it, yet who knows.

Thanks for the prompt fix.
-Emil

maintainer
#4 lore raw

PATCH 1/1 get_maintainer: Fix unexpected behavior for path/to//file (double slashes)

In reply to Joe Perches

get_maintainer behaves differently if there is a double sequential forward slash in a filename because the total number of slashes in a filename is used to match MAINTAINERS file patterns.

For example:

# (with double slash)

$ ./scripts/get_maintainer.pl -f drivers/gpu/drm//lima
David Airlie <[email protected]> (maintainer:DRM DRIVERS)
Daniel Vetter <[email protected]> (maintainer:DRM DRIVERS,commit_signer:3/42=7%)
Qiang Yu <[email protected]> (commit_signer:36/42=86%,authored:24/42=57%)
Vasily Khoruzhick <[email protected]> (commit_signer:26/42=62%)
Krzysztof Kozlowski <[email protected]> (commit_signer:5/42=12%,authored:5/42=12%)
Emil Velikov <[email protected]> (commit_signer:4/42=10%)
[email protected] (open list:DRM DRIVERS)
[email protected] (open list)

# (without double slash)

$ ./scripts/get_maintainer.pl -f drivers/gpu/drm/lima
Qiang Yu <[email protected]> (maintainer:DRM DRIVERS FOR LIMA)
David Airlie <[email protected]> (maintainer:DRM DRIVERS)
Daniel Vetter <[email protected]> (maintainer:DRM DRIVERS)
[email protected] (open list:DRM DRIVERS FOR LIMA)
[email protected] (moderated list:DRM DRIVERS FOR LIMA)
[email protected] (open list)

So reduce consecutive double slashes to a single slash by using File::Spec->canonpath().

from: https://perldoc.perl.org/File/Spec/Unix.html

canonpath()

No physical check on the filesystem, but a logical cleanup of a path. On UNIX eliminates successive slashes and successive "/.".

---
 scripts/get_maintainer.pl | 2 ++
 1 file changed, 2 insertions(+)
scripts/get_maintainer.pl +2 -0
index 6d973f3685f9..484d2fbf5921 100755
@@ -19,6 +19,7 @@ my $V = '0.26';
 use Getopt::Long qw(:config no_auto_abbrev);
 use Cwd;
 use File::Find;
+use File::Spec::Functions;
 
 my $cur_path = fastgetcwd() . '/';
 my $lk_path = "./";
@@ -532,6 +533,7 @@ if (!@ARGV) {
 
 foreach my $file (@ARGV) {
     if ($file ne "&STDIN") {
+	$file = canonpath($file);
 	##if $file is a directory and it lacks a trailing slash, add one
 	if ((-d $file)) {
 	    $file =~ s@([^/])$@$1/@;