line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Paranoid -- Paranoia support for safer programs |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# $Id: lib/Paranoid.pm, 2.10 2022/03/08 00:01:04 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
|
|
3973954
|
use 5.008; |
|
73
|
|
|
|
|
861
|
|
37
|
|
|
|
|
|
|
|
38
|
73
|
|
|
73
|
|
342
|
use strict; |
|
73
|
|
|
|
|
88
|
|
|
73
|
|
|
|
|
1262
|
|
39
|
73
|
|
|
73
|
|
271
|
use warnings; |
|
73
|
|
|
|
|
125
|
|
|
73
|
|
|
|
|
1991
|
|
40
|
73
|
|
|
73
|
|
333
|
use vars qw($VERSION @EXPORT @EXPORT_OK %EXPORT_TAGS); |
|
73
|
|
|
|
|
102
|
|
|
73
|
|
|
|
|
4327
|
|
41
|
73
|
|
|
73
|
|
500
|
use base qw(Exporter); |
|
73
|
|
|
|
|
115
|
|
|
73
|
|
|
|
|
12578
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
($VERSION) = ( q$Revision: 2.10 $ =~ /(\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
|
|
454
|
use constant PTRUE_ZERO => '0 but true'; |
|
73
|
|
|
|
|
163
|
|
|
73
|
|
|
|
|
5747
|
|
50
|
73
|
|
|
73
|
|
418
|
use constant DEFAULT_PATH => '/bin:/sbin:/usr/bin:/usr/sbin'; |
|
73
|
|
|
|
|
125
|
|
|
73
|
|
|
|
|
18776
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
##################################################################### |
53
|
|
|
|
|
|
|
# |
54
|
|
|
|
|
|
|
# Module code follows |
55
|
|
|
|
|
|
|
# |
56
|
|
|
|
|
|
|
##################################################################### |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
#BEGIN { |
59
|
|
|
|
|
|
|
#die "This module requires taint mode to be enabled!\n" unless |
60
|
|
|
|
|
|
|
# ${^TAINT} == 1; |
61
|
|
|
|
|
|
|
#delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; |
62
|
|
|
|
|
|
|
#$ENV{PATH} = '/bin:/sbin:/usr/bin:/usr/sbin'; |
63
|
|
|
|
|
|
|
#no ops qw(backtick system exec); |
64
|
|
|
|
|
|
|
# :subprocess = system, backtick, exec, fork, glob |
65
|
|
|
|
|
|
|
# :dangerous = syscall, dump, chroot |
66
|
|
|
|
|
|
|
# :others = mostly IPC stuff |
67
|
|
|
|
|
|
|
# :filesys_write = link, unlink, rename, mkdir, rmdir, chmod, |
68
|
|
|
|
|
|
|
# chown, fcntl |
69
|
|
|
|
|
|
|
# :sys_db = getpwnet, etc. |
70
|
|
|
|
|
|
|
#} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub psecureEnv (;$) { |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# Purpose: To delete taint-unsafe environment variables and to sanitize |
75
|
|
|
|
|
|
|
# the PATH variable |
76
|
|
|
|
|
|
|
# Returns: True (1) -- no matter what |
77
|
|
|
|
|
|
|
# Usage: psecureEnv(); |
78
|
|
|
|
|
|
|
|
79
|
73
|
|
|
73
|
1
|
6442
|
my $path = shift; |
80
|
|
|
|
|
|
|
|
81
|
73
|
100
|
|
|
|
351
|
$path = DEFAULT_PATH unless defined $path; |
82
|
|
|
|
|
|
|
|
83
|
73
|
|
|
|
|
881
|
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; |
84
|
73
|
|
|
|
|
2416
|
$ENV{PATH} = $path; |
85
|
73
|
50
|
|
|
|
434
|
if ( exists $ENV{TERM} ) { |
86
|
73
|
50
|
|
|
|
653
|
if ( $ENV{TERM} =~ /^([\w\+\.\-]+)$/s ) { |
87
|
73
|
|
|
|
|
647
|
$ENV{TERM} = $1; |
88
|
|
|
|
|
|
|
} else { |
89
|
0
|
|
|
|
|
0
|
$ENV{TERM} = 'vt100'; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
73
|
|
|
|
|
215
|
return 1; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
{ |
97
|
|
|
|
|
|
|
my $errorMsg = ''; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub ERROR : lvalue { |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# Purpose: To store/retrieve a string error message |
102
|
|
|
|
|
|
|
# Returns: Scalar string |
103
|
|
|
|
|
|
|
# Usage: $errMsg = Paranoid::ERROR; |
104
|
|
|
|
|
|
|
# Usage: Paranoid::ERROR = $errMsg; |
105
|
|
|
|
|
|
|
|
106
|
142
|
|
|
142
|
1
|
517
|
$errorMsg; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
__END__ |