user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 0/3] lei pathname canonicalization fixes
@ 2021-08-11 11:26  7% Eric Wong
  2021-08-11 11:26  6% ` [PATCH 1/3] treewide: use *nix-specific dirname regexps Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2021-08-11 11:26 UTC (permalink / raw)
  To: meta

Pathnames with "x/../y" components weren't being canonicalized
properly after creation, and some of it was being put into the
lei_mail_sync.sqlite3 DB and configs for saved searches.

This will become more important as we start using inotify more
to track keyword changes on messages.

Eric Wong (3):
  treewide: use *nix-specific dirname regexps
  lei_saved_search: canonicalized relative save paths
  lei: attempt to canonicalize away "/../" pathnames

 lib/PublicInbox/IMAPTracker.pm    |  4 ++--
 lib/PublicInbox/LEI.pm            | 16 +++++++++++-----
 lib/PublicInbox/LeiALE.pm         |  8 ++++----
 lib/PublicInbox/LeiBlob.pm        |  4 ++--
 lib/PublicInbox/LeiInit.pm        |  3 +--
 lib/PublicInbox/LeiLcat.pm        |  2 +-
 lib/PublicInbox/LeiOverview.pm    |  2 +-
 lib/PublicInbox/LeiQuery.pm       |  2 +-
 lib/PublicInbox/LeiRediff.pm      |  2 +-
 lib/PublicInbox/LeiSavedSearch.pm |  9 ++++++++-
 lib/PublicInbox/LeiUp.pm          |  2 +-
 lib/PublicInbox/OverIdx.pm        |  4 ++--
 lib/PublicInbox/Xapcmd.pm         |  5 ++---
 script/public-inbox-init          |  3 +--
 t/init.t                          |  1 -
 t/lei-q-save.t                    |  9 +++++++++
 t/lei_xsearch.t                   |  8 +++++---
 17 files changed, 52 insertions(+), 32 deletions(-)

^ permalink raw reply	[relevance 7%]

* [PATCH 1/3] treewide: use *nix-specific dirname regexps
  2021-08-11 11:26  7% [PATCH 0/3] lei pathname canonicalization fixes Eric Wong
@ 2021-08-11 11:26  6% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2021-08-11 11:26 UTC (permalink / raw)
  To: meta

None of our code elsewhere accounts for non-*nix pathnames and
it's not worth our time to start.  So stop wasting CPU cycles
giving the illusion that we'd care about non-*nix pathnames.
---
 lib/PublicInbox/IMAPTracker.pm | 4 ++--
 lib/PublicInbox/LEI.pm         | 2 +-
 lib/PublicInbox/OverIdx.pm     | 4 ++--
 lib/PublicInbox/Xapcmd.pm      | 5 ++---
 script/public-inbox-init       | 3 +--
 t/init.t                       | 1 -
 6 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/lib/PublicInbox/IMAPTracker.pm b/lib/PublicInbox/IMAPTracker.pm
index 5eb33cf7..2fd66440 100644
--- a/lib/PublicInbox/IMAPTracker.pm
+++ b/lib/PublicInbox/IMAPTracker.pm
@@ -75,9 +75,9 @@ sub new {
 	}
 	if (!-f $dbname) {
 		require File::Path;
-		require File::Basename;
 		require PublicInbox::Spawn;
-		File::Path::mkpath(File::Basename::dirname($dbname));
+		my ($dir) = ($dbname =~ m!(.*?/)[^/]+\z!);
+		File::Path::mkpath($dir);
 		open my $fh, '+>>', $dbname or die "failed to open $dbname: $!";
 		PublicInbox::Spawn::nodatacow_fd(fileno($fh));
 	}
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index e6f763e1..be4754df 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -798,7 +798,7 @@ sub _lei_cfg ($;$) {
 			delete $self->{cfg};
 			return bless {}, 'PublicInbox::Config';
 		}
-		my (undef, $cfg_dir, undef) = File::Spec->splitpath($f);
+		my ($cfg_dir) = ($f =~ m!(.*?/)[^/]+\z!);
 		-d $cfg_dir or mkpath($cfg_dir) or die "mkpath($cfg_dir): $!\n";
 		open my $fh, '>>', $f or die "open($f): $!\n";
 		@st = stat($fh) or die "fstat($f): $!\n";
diff --git a/lib/PublicInbox/OverIdx.pm b/lib/PublicInbox/OverIdx.pm
index 8f7cf2bb..e0893337 100644
--- a/lib/PublicInbox/OverIdx.pm
+++ b/lib/PublicInbox/OverIdx.pm
@@ -463,8 +463,8 @@ sub create {
 	};
 	unless (-r $fn) {
 		require File::Path;
-		require File::Basename;
-		File::Path::mkpath(File::Basename::dirname($fn));
+		my ($dir) = ($fn =~ m!(.*?/)[^/]+\z!);
+		File::Path::mkpath($dir);
 	}
 	# create the DB:
 	PublicInbox::Over::dbh($self);
diff --git a/lib/PublicInbox/Xapcmd.pm b/lib/PublicInbox/Xapcmd.pm
index 8b8958c7..588e7b94 100644
--- a/lib/PublicInbox/Xapcmd.pm
+++ b/lib/PublicInbox/Xapcmd.pm
@@ -8,7 +8,6 @@ use PublicInbox::Over;
 use PublicInbox::SearchIdx;
 use File::Temp 0.19 (); # ->newdir
 use File::Path qw(remove_tree);
-use File::Basename qw(dirname);
 use POSIX qw(WNOHANG _exit);
 
 # support testing with dev versions of Xapian which installs
@@ -199,7 +198,7 @@ sub prepare_run {
 			warn
 "--reshard=$reshard ignored for v1 $ibx->{inboxdir}\n";
 		}
-		my $dir = dirname($old);
+		my ($dir) = ($old =~ m!(.*?/)[^/]+/*\z!);
 		same_fs_or_die($dir, $old);
 		my $v = PublicInbox::Search::SCHEMA_VERSION();
 		my $wip = File::Temp->newdir("xapian$v-XXXX", DIR => $dir);
@@ -431,7 +430,7 @@ sub cpdb ($$) { # cb_spawn callback
 	my ($tmp, $ft);
 	local %SIG = %SIG;
 	if ($opt->{compact}) {
-		my $dir = dirname($new);
+		my ($dir) = ($new =~ m!(.*?/)[^/]+/*\z!);
 		same_fs_or_die($dir, $new);
 		$ft = File::Temp->newdir("$new.compact-XXXX", DIR => $dir);
 		setup_signals();
diff --git a/script/public-inbox-init b/script/public-inbox-init
index 6fac4d18..ced88235 100755
--- a/script/public-inbox-init
+++ b/script/public-inbox-init
@@ -93,8 +93,7 @@ $ng =~ m![^A-Za-z0-9/_\.\-\~\@\+\=:]! and
 
 require PublicInbox::Config;
 my $pi_config = PublicInbox::Config->default_file;
-require File::Basename;
-my $dir = File::Basename::dirname($pi_config);
+my ($dir) = ($pi_config =~ m!(.*?/)[^/]+\z!);
 require File::Path;
 File::Path::mkpath($dir); # will croak on fatal errors
 
diff --git a/t/init.t b/t/init.t
index 7382e05b..efa3314d 100644
--- a/t/init.t
+++ b/t/init.t
@@ -6,7 +6,6 @@ use Test::More;
 use PublicInbox::Config;
 use PublicInbox::TestCommon;
 use PublicInbox::Admin;
-use File::Basename;
 my ($tmpdir, $for_destroy) = tmpdir();
 sub quiet_fail {
 	my ($cmd, $msg) = @_;

^ permalink raw reply related	[relevance 6%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2021-08-11 11:26  7% [PATCH 0/3] lei pathname canonicalization fixes Eric Wong
2021-08-11 11:26  6% ` [PATCH 1/3] treewide: use *nix-specific dirname regexps Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).