Issues (4069)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

modules/Administration/UpgradeWizardCommon.php (8 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3
/*********************************************************************************
4
 * SugarCRM Community Edition is a customer relationship management program developed by
5
 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
6
7
 * SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd.
8
 * Copyright (C) 2011 - 2014 Salesagility Ltd.
9
 *
10
 * This program is free software; you can redistribute it and/or modify it under
11
 * the terms of the GNU Affero General Public License version 3 as published by the
12
 * Free Software Foundation with the addition of the following permission added
13
 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
14
 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
15
 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
16
 * 
17
 * This program is distributed in the hope that it will be useful, but WITHOUT
18
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19
 * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
20
 * details.
21
 * 
22
 * You should have received a copy of the GNU Affero General Public License along with
23
 * this program; if not, see http://www.gnu.org/licenses or write to the Free
24
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25
 * 02110-1301 USA.
26
 * 
27
 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
28
 * SW2-130, Cupertino, CA 95014, USA. or at email address [email protected].
29
 * 
30
 * The interactive user interfaces in modified source and object code versions
31
 * of this program must display Appropriate Legal Notices, as required under
32
 * Section 5 of the GNU Affero General Public License version 3.
33
 * 
34
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
35
 * these Appropriate Legal Notices must retain the display of the "Powered by
36
 * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
37
 * reasonably feasible for  technical reasons, the Appropriate Legal Notices must
38
 * display the words  "Powered by SugarCRM" and "Supercharged by SuiteCRM".
39
 ********************************************************************************/
40
41
42
if (!is_admin($GLOBALS['current_user'])) {
43
    sugar_die($GLOBALS['app_strings']['ERR_NOT_ADMIN']);
44
}
45
46
require_once('include/utils/db_utils.php');
47
require_once('include/utils/zip_utils.php');
48
49
// increase the cuttoff time to 1 hour
50
ini_set("max_execution_time", "3600");
51
52
if( isset( $_REQUEST['view'] ) && ($_REQUEST['view'] != "") ){
53
    $view = $_REQUEST['view'];
54
    if( $view != "default" && $view != "module" ){
55
        die($mod_strings['ERR_UW_INVALID_VIEW']);
56
    }
57
}
58
else{
59
    die($mod_strings['ERR_UW_NO_VIEW']);
60
}
61
$form_action = "index.php?module=Administration&view=" . $view . "&action=UpgradeWizard";
62
63
64
$base_upgrade_dir       = "upload://upgrades";
65
$base_tmp_upgrade_dir   = sugar_cached('upgrades/temp');
66
67
$GLOBALS['subdirs'] = array('full', 'langpack', 'module', 'patch', 'theme');
68
// array of special scripts that are executed during (un)installation-- key is type of script, value is filename
69
70
if(!defined('SUGARCRM_PRE_INSTALL_FILE'))
71
{
72
	define('SUGARCRM_PRE_INSTALL_FILE', 'scripts/pre_install.php');
73
	define('SUGARCRM_POST_INSTALL_FILE', 'scripts/post_install.php');
74
	define('SUGARCRM_PRE_UNINSTALL_FILE', 'scripts/pre_uninstall.php');
75
	define('SUGARCRM_POST_UNINSTALL_FILE', 'scripts/post_uninstall.php');
76
}
77
$script_files = array(
78
	"pre-install" => constant('SUGARCRM_PRE_INSTALL_FILE'),
79
	"post-install" => constant('SUGARCRM_POST_INSTALL_FILE'),
80
	"pre-uninstall" => constant('SUGARCRM_PRE_UNINSTALL_FILE'),
81
	"post-uninstall" => constant('SUGARCRM_POST_UNINSTALL_FILE'),
82
);
83
84
85
86
function extractFile( $zip_file, $file_in_zip ){
0 ignored issues
show
The function extractFile() has been defined more than once; this definition is ignored, only the first definition in install/install_utils.php (L1750-1754) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
87
    global $base_tmp_upgrade_dir;
88
	if(empty($base_tmp_upgrade_dir)){
89
    	$base_tmp_upgrade_dir   = sugar_cached("upgrades/temp");
90
    }
91
    $my_zip_dir = mk_temp_dir( $base_tmp_upgrade_dir );
92
    register_shutdown_function('rmdir_recursive', $my_zip_dir);
93
    unzip_file( $zip_file, $file_in_zip, $my_zip_dir );
94
    return( "$my_zip_dir/$file_in_zip" );
95
}
96
97
function extractManifest( $zip_file ){
0 ignored issues
show
The function extractManifest() has been defined more than once; this definition is ignored, only the first definition in install/install_utils.php (L1758-1760) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
98
    return( extractFile( $zip_file, "manifest.php" ) );
0 ignored issues
show
The call to extractFile() misses a required argument $base_tmp_upgrade_dir.

This check looks for function calls that miss required arguments.

Loading history...
99
}
100
101
function getInstallType( $type_string ){
0 ignored issues
show
The function getInstallType() has been defined more than once; this definition is ignored, only the first definition in install/install_utils.php (L1893-1903) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
102
    // detect file type
103
    global $subdirs;
104
105
    foreach( $subdirs as $subdir ){
106
        if( preg_match( "#/$subdir/#", $type_string ) ){
107
            return( $subdir );
108
        }
109
    }
110
    // return empty if no match
111
    return( "" );
112
}
113
114
function getImageForType( $type ){
115
116
    $icon = "";
117
    switch( $type ){
118
        case "full":
119
            $icon = SugarThemeRegistry::current()->getImage("Upgrade", "",null,null,'.gif',$mod_strings['LBL_DST_UPGRADE']);
120
            break;
121
        case "langpack":
122
            $icon = SugarThemeRegistry::current()->getImage("LanguagePacks", "",null,null,'.gif',$mod_strings['LBL_LANGUAGE_PACKS'] );
123
            break;
124
        case "module":
125
            $icon = SugarThemeRegistry::current()->getImage("ModuleLoader", "",null,null,'.gif',$mod_strings['LBL_MODULE_LOADER_TITLE']);
126
            break;
127
        case "patch":
128
            $icon = SugarThemeRegistry::current()->getImage("PatchUpgrades", "",null,null,'.gif',$mod_strings['LBL_PATCH_UPGRADES'] );
129
            break;
130
        case "theme":
131
            $icon = SugarThemeRegistry::current()->getImage("Themes", "",null,null,'.gif',$mod_strings['LBL_THEME_SETTINGS'] );
132
            break;
133
        default:
134
            break;
135
    }
136
    return( $icon );
137
}
138
139
function getLanguagePackName( $the_file ){
0 ignored issues
show
The function getLanguagePackName() has been defined more than once; this definition is ignored, only the first definition in install/install_utils.php (L492-498) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
140
    global $app_list_strings;
141
    require_once( "$the_file" );
142
    if( isset( $app_list_strings["language_pack_name"] ) ){
143
        return( $app_list_strings["language_pack_name"] );
144
    }
145
    return( "" );
146
}
147
148
function getUITextForType( $type ){
149
	$type = 'LBL_UW_TYPE_'.strtoupper($type);
150
	global $mod_strings;
151
	return $mod_strings[$type];
152
}
153
154
function getUITextForMode( $mode ){
155
    $mode = 'LBL_UW_MODE_'.strtoupper($mode);
156
    global $mod_strings;
157
    return $mod_strings[$mode];
158
}
159
160
function validate_manifest( $manifest ){
0 ignored issues
show
The function validate_manifest() has been defined more than once; this definition is ignored, only the first definition in install/install_utils.php (L1835-1889) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
161
    // takes a manifest.php manifest array and validates contents
162
    global $subdirs;
163
    global $sugar_version;
164
    global $sugar_flavor;
165
	global $mod_strings;
166
167
    if( !isset($manifest['type']) ){
168
        die($mod_strings['ERROR_MANIFEST_TYPE']);
169
    }
170
    $type = $manifest['type'];
171
    if( getInstallType( "/$type/" ) == "" ){
172
        die($mod_strings['ERROR_PACKAGE_TYPE']. ": '" . $type . "'." );
173
    }
174
175
    if( isset($manifest['acceptable_sugar_versions']) ){
176
        $version_ok = false;
177
        $matches_empty = true;
178
        if( isset($manifest['acceptable_sugar_versions']['exact_matches']) ){
179
            $matches_empty = false;
180
            foreach( $manifest['acceptable_sugar_versions']['exact_matches'] as $match ){
181
                if( $match == $sugar_version ){
182
                    $version_ok = true;
183
                }
184
            }
185
        }
186
        if( !$version_ok && isset($manifest['acceptable_sugar_versions']['regex_matches']) ){
187
            $matches_empty = false;
188
            foreach( $manifest['acceptable_sugar_versions']['regex_matches'] as $match ){
189
                if( preg_match( "/$match/", $sugar_version ) ){
190
                    $version_ok = true;
191
                }
192
            }
193
        }
194
195
        if( !$matches_empty && !$version_ok ){
196
            die( $mod_strings['ERROR_VERSION_INCOMPATIBLE'] . $sugar_version );
197
        }
198
    }
199
200
    if( isset($manifest['acceptable_sugar_flavors']) && sizeof($manifest['acceptable_sugar_flavors']) > 0 ){
201
        $flavor_ok = false;
202
        foreach( $manifest['acceptable_sugar_flavors'] as $match ){
203
            if( $match == $sugar_flavor ){
204
                $flavor_ok = true;
205
            }
206
        }
207
        if( !$flavor_ok ){
208
            die( $mod_strings['ERROR_FLAVOR_INCOMPATIBLE'] . $sugar_flavor );
209
        }
210
    }
211
}
212
213
function getDiffFiles($unzip_dir, $install_file, $is_install = true, $previous_version = ''){
214
	//require_once($unzip_dir . '/manifest.php');
215
	global $installdefs;
216
	if(!empty($previous_version)){
217
		//check if the upgrade path exists
218
		if(!empty($upgrade_manifest)){
0 ignored issues
show
The variable $upgrade_manifest seems to never exist, and therefore empty should always return true. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
219
			if(!empty($upgrade_manifest['upgrade_paths'])){
220
				if(!empty($upgrade_manifest['upgrade_paths'][$previous_version])){
221
					$installdefs = 	$upgrade_manifest['upgrade_paths'][$previous_version];
222
				}
223
			}//fi
224
		}//fi
225
	}//fi
226
	$modified_files = array();
227
	if(!empty($installdefs['copy'])){
228
		foreach($installdefs['copy'] as $cp){
229
			$cp['to'] = clean_path(str_replace('<basepath>', $unzip_dir, $cp['to']));
230
			$restore_path = remove_file_extension(urldecode($install_file))."-restore/";
231
			$backup_path = clean_path($restore_path.$cp['to'] );
232
			//check if this file exists in the -restore directory
233
			if(file_exists($backup_path)){
234
				//since the file exists, then we want do an md5 of the install version and the file system version
235
				$from = $backup_path;
236
				$needle = $restore_path;
237
				if(!$is_install){
238
					$from = str_replace('<basepath>', $unzip_dir, $cp['from']);
239
					$needle = $unzip_dir;
240
				}
241
				$files_found = md5DirCompare($from.'/', $cp['to'].'/', array('.svn'), false);
0 ignored issues
show
The call to md5DirCompare() has too many arguments starting with false.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
242
				if(count($files_found > 0)){
243
					foreach($files_found as $key=>$value){
244
						$modified_files[] = str_replace($needle, '', $key);
245
					}
246
				}
247
			}//fi
248
		}//rof
249
	}//fi
250
	return $modified_files;
251
}
252