| 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 | # <https://www.gnu.org/licenses/gpl-1.0.html> as published by the | ||||||||||
| 12 | # Free Software Foundation <http://www.fsf.org/>; either version 1 | ||||||||||
| 13 | # <https://www.gnu.org/licenses/gpl-1.0.html>, or any later version | ||||||||||
| 14 | # <https://www.gnu.org/licenses/license-list.html#GNUGPL>, or | ||||||||||
| 15 | # b) the Artistic License 2.0 | ||||||||||
| 16 | # <https://opensource.org/licenses/Artistic-2.0>, | ||||||||||
| 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 | 72 | ▶ | use 5.008; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 37 | |||||||||||
| 38 | 72 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 39 | 72 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 40 | 72 | ▶ | use vars qw($VERSION @EXPORT @EXPORT_OK %EXPORT_TAGS); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 41 | 72 | ▶ | use base qw(Exporter); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 42 | |||||||||||
| 43 | 72 | ($VERSION) = ( q$Revision: 2.10 $ =~ /(\d+(?:\.\d+)+)/sm ); | |||||||||
| 44 | |||||||||||
| 45 | 72 | @EXPORT = qw(psecureEnv); | |||||||||
| 46 | 72 | @EXPORT_OK = ( @EXPORT, qw(PTRUE_ZERO) ); | |||||||||
| 47 | 72 | %EXPORT_TAGS = ( all => [@EXPORT_OK], ); | |||||||||
| 48 | |||||||||||
| 49 | 72 | ▶ | use constant PTRUE_ZERO => '0 but true'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 50 | 72 | ▶ | use constant DEFAULT_PATH => '/bin:/sbin:/usr/bin:/usr/sbin'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | 72 | ▶ | sub psecureEnv (;$) { | ||||||||
|
Subroutine
psecureEnv: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||
| 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 | 72 | my $path = shift; | |||||||||
| 80 | |||||||||||
| 81 | 72 | ▶ | $path = DEFAULT_PATH unless defined $path; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | |||||||||||
| 83 | 72 | delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; | |||||||||
| 84 | 72 | $ENV{PATH} = $path; | |||||||||
| 85 | 72 | ▶ | if ( exists $ENV{TERM} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 86 | 72 | ▶ | if ( $ENV{TERM} =~ /^([\w\+\.\-]+)$/s ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 87 | 72 | $ENV{TERM} = $1; | |||||||||
| 88 | } else { | ||||||||||
| 89 | 0 | $ENV{TERM} = 'vt100'; | |||||||||
| 90 | } | ||||||||||
| 91 | } | ||||||||||
| 92 | |||||||||||
| 93 | 72 | return 1; | |||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | { | ||||||||||
| 97 | 72 | my $errorMsg = ''; | |||||||||
| 98 | |||||||||||
| 99 | 146 | ▶ | sub ERROR : lvalue { | ||||||||
|
Subroutine
ERROR: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 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 | 146 | $errorMsg; | |||||||||
| 107 | } | ||||||||||
| 108 | } | ||||||||||
| 109 | |||||||||||
| 110 | 72 | 1; | |||||||||
| 111 | |||||||||||
| 112 | __END__ | ||||||||||