| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Paranoid -- Paranoia support for safer programs |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# $Id: lib/Paranoid.pm, 2.09 2021/12/28 15:46:49 acorliss Exp $ |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
# (c) 2005 - 2020, Arthur Corliss (corliss@digitalmages.com) |
|
6
|
|
|
|
|
|
|
# (tm) 2008 - 2020, Paranoid Inc. (www.paranoid.com) |
|
7
|
|
|
|
|
|
|
# This software is free software. Similar to Perl, you can redistribute it |
|
8
|
|
|
|
|
|
|
# and/or modify it under the terms of either: |
|
9
|
|
|
|
|
|
|
# |
|
10
|
|
|
|
|
|
|
# a) the GNU General Public License |
|
11
|
|
|
|
|
|
|
# as published by the |
|
12
|
|
|
|
|
|
|
# Free Software Foundation ; either version 1 |
|
13
|
|
|
|
|
|
|
# , or any later version |
|
14
|
|
|
|
|
|
|
# , or |
|
15
|
|
|
|
|
|
|
# b) the Artistic License 2.0 |
|
16
|
|
|
|
|
|
|
# , |
|
17
|
|
|
|
|
|
|
# |
|
18
|
|
|
|
|
|
|
# subject to the following additional term: No trademark rights to |
|
19
|
|
|
|
|
|
|
# "Paranoid" have been or are conveyed under any of the above licenses. |
|
20
|
|
|
|
|
|
|
# However, "Paranoid" may be used fairly to describe this unmodified |
|
21
|
|
|
|
|
|
|
# software, in good faith, but not as a trademark. |
|
22
|
|
|
|
|
|
|
# |
|
23
|
|
|
|
|
|
|
# (c) 2005 - 2020, Arthur Corliss (corliss@digitalmages.com) |
|
24
|
|
|
|
|
|
|
# (tm) 2008 - 2020, Paranoid Inc. (www.paranoid.com) |
|
25
|
|
|
|
|
|
|
# |
|
26
|
|
|
|
|
|
|
##################################################################### |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
##################################################################### |
|
29
|
|
|
|
|
|
|
# |
|
30
|
|
|
|
|
|
|
# Environment definitions |
|
31
|
|
|
|
|
|
|
# |
|
32
|
|
|
|
|
|
|
##################################################################### |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
package Paranoid; |
|
35
|
|
|
|
|
|
|
|
|
36
|
73
|
|
|
73
|
|
4997805
|
use 5.008; |
|
|
73
|
|
|
|
|
1018
|
|
|
37
|
|
|
|
|
|
|
|
|
38
|
73
|
|
|
73
|
|
410
|
use strict; |
|
|
73
|
|
|
|
|
128
|
|
|
|
73
|
|
|
|
|
1737
|
|
|
39
|
73
|
|
|
73
|
|
350
|
use warnings; |
|
|
73
|
|
|
|
|
130
|
|
|
|
73
|
|
|
|
|
2562
|
|
|
40
|
73
|
|
|
73
|
|
346
|
use vars qw($VERSION @EXPORT @EXPORT_OK %EXPORT_TAGS); |
|
|
73
|
|
|
|
|
137
|
|
|
|
73
|
|
|
|
|
5499
|
|
|
41
|
73
|
|
|
73
|
|
569
|
use base qw(Exporter); |
|
|
73
|
|
|
|
|
167
|
|
|
|
73
|
|
|
|
|
15178
|
|
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
($VERSION) = ( q$Revision: 2.09 $ =~ /(\d+(?:\.\d+)+)/sm ); |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
@EXPORT = qw(psecureEnv); |
|
46
|
|
|
|
|
|
|
@EXPORT_OK = ( @EXPORT, qw(PTRUE_ZERO) ); |
|
47
|
|
|
|
|
|
|
%EXPORT_TAGS = ( all => [@EXPORT_OK], ); |
|
48
|
|
|
|
|
|
|
|
|
49
|
73
|
|
|
73
|
|
568
|
use constant PTRUE_ZERO => '0 but true'; |
|
|
73
|
|
|
|
|
217
|
|
|
|
73
|
|
|
|
|
26770
|
|
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
##################################################################### |
|
52
|
|
|
|
|
|
|
# |
|
53
|
|
|
|
|
|
|
# Module code follows |
|
54
|
|
|
|
|
|
|
# |
|
55
|
|
|
|
|
|
|
##################################################################### |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
#BEGIN { |
|
58
|
|
|
|
|
|
|
#die "This module requires taint mode to be enabled!\n" unless |
|
59
|
|
|
|
|
|
|
# ${^TAINT} == 1; |
|
60
|
|
|
|
|
|
|
#delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; |
|
61
|
|
|
|
|
|
|
#$ENV{PATH} = '/bin:/sbin:/usr/bin:/usr/sbin'; |
|
62
|
|
|
|
|
|
|
#no ops qw(backtick system exec); |
|
63
|
|
|
|
|
|
|
# :subprocess = system, backtick, exec, fork, glob |
|
64
|
|
|
|
|
|
|
# :dangerous = syscall, dump, chroot |
|
65
|
|
|
|
|
|
|
# :others = mostly IPC stuff |
|
66
|
|
|
|
|
|
|
# :filesys_write = link, unlink, rename, mkdir, rmdir, chmod, |
|
67
|
|
|
|
|
|
|
# chown, fcntl |
|
68
|
|
|
|
|
|
|
# :sys_db = getpwnet, etc. |
|
69
|
|
|
|
|
|
|
#} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub psecureEnv (;$) { |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# Purpose: To delete taint-unsafe environment variables and to sanitize |
|
74
|
|
|
|
|
|
|
# the PATH variable |
|
75
|
|
|
|
|
|
|
# Returns: True (1) -- no matter what |
|
76
|
|
|
|
|
|
|
# Usage: psecureEnv(); |
|
77
|
|
|
|
|
|
|
|
|
78
|
73
|
|
|
73
|
1
|
7925
|
my $path = shift; |
|
79
|
|
|
|
|
|
|
|
|
80
|
73
|
100
|
|
|
|
369
|
$path = '/bin:/usr/bin' unless defined $path; |
|
81
|
|
|
|
|
|
|
|
|
82
|
73
|
|
|
|
|
1092
|
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; |
|
83
|
73
|
|
|
|
|
2083
|
$ENV{PATH} = $path; |
|
84
|
73
|
50
|
|
|
|
569
|
if ( exists $ENV{TERM} ) { |
|
85
|
73
|
50
|
|
|
|
782
|
if ( $ENV{TERM} =~ /^([\w\+\.\-]+)$/s ) { |
|
86
|
73
|
|
|
|
|
398
|
$ENV{TERM} = $1; |
|
87
|
|
|
|
|
|
|
} else { |
|
88
|
0
|
|
|
|
|
0
|
$ENV{TERM} = 'vt100'; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
73
|
|
|
|
|
285
|
return 1; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
{ |
|
96
|
|
|
|
|
|
|
my $errorMsg = ''; |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub ERROR : lvalue { |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# Purpose: To store/retrieve a string error message |
|
101
|
|
|
|
|
|
|
# Returns: Scalar string |
|
102
|
|
|
|
|
|
|
# Usage: $errMsg = Paranoid::ERROR; |
|
103
|
|
|
|
|
|
|
# Usage: Paranoid::ERROR = $errMsg; |
|
104
|
|
|
|
|
|
|
|
|
105
|
142
|
|
|
142
|
1
|
558
|
$errorMsg; |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
__END__ |