line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Paranoid -- Paranoia support for safer programs |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# $Id: lib/Paranoid.pm, 2.08 2020/12/31 12:10:06 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
|
52
|
|
|
52
|
|
3382941
|
use 5.008; |
|
52
|
|
|
|
|
600
|
|
37
|
|
|
|
|
|
|
|
38
|
52
|
|
|
52
|
|
280
|
use strict; |
|
52
|
|
|
|
|
99
|
|
|
52
|
|
|
|
|
1052
|
|
39
|
52
|
|
|
52
|
|
219
|
use warnings; |
|
52
|
|
|
|
|
97
|
|
|
52
|
|
|
|
|
1445
|
|
40
|
52
|
|
|
52
|
|
278
|
use vars qw($VERSION @EXPORT @EXPORT_OK %EXPORT_TAGS); |
|
52
|
|
|
|
|
107
|
|
|
52
|
|
|
|
|
4217
|
|
41
|
52
|
|
|
52
|
|
382
|
use base qw(Exporter); |
|
52
|
|
|
|
|
109
|
|
|
52
|
|
|
|
|
9290
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
($VERSION) = ( q$Revision: 2.08 $ =~ /(\d+(?:\.\d+)+)/sm ); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
@EXPORT = qw(psecureEnv); |
46
|
|
|
|
|
|
|
@EXPORT_OK = ( @EXPORT, qw(PTRUE_ZERO) ); |
47
|
|
|
|
|
|
|
%EXPORT_TAGS = ( all => [@EXPORT_OK], ); |
48
|
|
|
|
|
|
|
|
49
|
52
|
|
|
52
|
|
408
|
use constant PTRUE_ZERO => '0 but true'; |
|
52
|
|
|
|
|
107
|
|
|
52
|
|
|
|
|
18097
|
|
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
|
52
|
|
|
52
|
1
|
5777
|
my $path = shift; |
79
|
|
|
|
|
|
|
|
80
|
52
|
100
|
|
|
|
287
|
$path = '/bin:/usr/bin' unless defined $path; |
81
|
|
|
|
|
|
|
|
82
|
52
|
|
|
|
|
726
|
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; |
83
|
52
|
|
|
|
|
1585
|
$ENV{PATH} = $path; |
84
|
52
|
50
|
|
|
|
355
|
if ( exists $ENV{TERM} ) { |
85
|
52
|
50
|
|
|
|
489
|
if ( $ENV{TERM} =~ /^([\w\+\.\-]+)$/s ) { |
86
|
52
|
|
|
|
|
298
|
$ENV{TERM} = $1; |
87
|
|
|
|
|
|
|
} else { |
88
|
0
|
|
|
|
|
0
|
$ENV{TERM} = 'vt100'; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
52
|
|
|
|
|
174
|
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
|
53
|
|
|
53
|
1
|
309
|
$errorMsg; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
__END__ |