File: interp-do-not-set-PYTHONPATH-environment-variable-to.patch

package info (click to toggle)
needrestart 3.6-4%2Bdeb12u3
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 936 kB
  • sloc: perl: 3,371; sh: 277; makefile: 82
file content (54 lines) | stat: -rw-r--r-- 1,670 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
From 4c1fa7037c54224cef1e077c5ebdc7f2cfc83799 Mon Sep 17 00:00:00 2001
From: Thomas Liske <thomas@fiasko-nw.net>
Date: Sat, 12 Oct 2024 18:57:39 +0200
Subject: [PATCH 2/5] interp: do not set PYTHONPATH environment variable to
 prevent a LPE

---
 perl/lib/NeedRestart/Interp/Python.pm | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/perl/lib/NeedRestart/Interp/Python.pm b/perl/lib/NeedRestart/Interp/Python.pm
index 097ac05..7a7002e 100644
--- a/perl/lib/NeedRestart/Interp/Python.pm
+++ b/perl/lib/NeedRestart/Interp/Python.pm
@@ -190,16 +190,16 @@ sub files {
     }
 
     # prepare include path environment variable
-    my %e = nr_parse_env($pid);
+    my @path;
     local %ENV;
+
+    # get include path from env
+    my %e = nr_parse_env($pid);
     if(exists($e{PYTHONPATH})) {
-	$ENV{PYTHONPATH} = $e{PYTHONPATH};
-    }
-    elsif(exists($ENV{PYTHONPATH})) {
-	delete($ENV{PYTHONPATH});
+	@path = map { "/proc/$pid/root/$_"; } split(':', $e{PYTHONPATH});
     }
 
-    # get include path
+    # get include path from sys.path
     my ($pyread, $pywrite) = nr_fork_pipe2($self->{debug}, $ptable->{exec}, '-');
     print $pywrite "import sys\nprint(sys.path)\n";
     close($pywrite);
@@ -207,12 +207,11 @@ sub files {
     close($pyread);
 
     # look for module source files
-    my @path;
     if(defined($path)) {
 	chomp($path);
 	$path =~ s/^\['//;
 	$path =~ s/'\$//;
-	@path = map { "/proc/$pid/root/$_"; } split("', '", $path);
+	push(@path, map { "/proc/$pid/root/$_"; } split("', '", $path));
     }
     else {
 	print STDERR "$LOGPREF #$pid: failed to retrieve include path\n" if($self->{debug});
-- 
2.39.5