From 39faf86e122fefe4a8093f3b6609658c56c696c0 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Mon, 8 Jul 2019 05:30:37 +0200 Subject: libinterimap: use directories relative to $HOME for the XDG defaults. Previously getpwuid() was called to determine the user's home directory, while the XDG specification explicitely mentions $HOME. Conveniently our docs always mentioned ~/, which on POSIX-compliant systems expands to the value of the variable HOME (and the result is unspecified when the variable is unset). Cf. Shell and Utilities volume of POSIX.1-2017, sec. 2.6.1: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_01 --- Changelog | 7 +++++++ lib/Net/IMAP/InterIMAP.pm | 6 ++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Changelog b/Changelog index 84a62b6..d429932 100644 --- a/Changelog +++ b/Changelog @@ -69,6 +69,13 @@ interimap (0.5) upstream; the 'foreign_keys' PRAGMA during a transaction is a documented no-op). - interimap: fix handling of mod-sequence values greater or equal than 2 << 63. + - libinterimap: use directories relative to $HOME for the XDG + environment variables default values. Previously getpwuid() was + called to determine the user's home directory, while the XDG + specification explicitely mentions $HOME. Conveniently our docs + always mentioned ~/, which on POSIX-compliant systems expands to the + value of the variable HOME. (Cf. Shell and Utilities volume of + POSIX.1-2017, sec. 2.6.1.) -- Guilhem Moulin Fri, 10 May 2019 00:58:14 +0200 diff --git a/lib/Net/IMAP/InterIMAP.pm b/lib/Net/IMAP/InterIMAP.pm index 19895c4..aacc8e7 100644 --- a/lib/Net/IMAP/InterIMAP.pm +++ b/lib/Net/IMAP/InterIMAP.pm @@ -92,11 +92,9 @@ sub xdg_basedir($$$$) { return $path if $path =~ /\A\//; my $basedir = $ENV{$xdg_variable}; - unless (defined $basedir) { - my @getent = getpwuid($>); - $basedir = $getent[7] ."/". $default; - } + $basedir = ($ENV{HOME} // "") ."/". $default unless defined $basedir; die "No such directory: ", $basedir unless -d $basedir; + $basedir .= "/".$subdir; $basedir =~ /\A(\/\p{Print}+)\z/ or die "Insecure $basedir"; $basedir = $1; -- cgit v1.2.3