Issues (1752)

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.

func/dbwrite.php (2 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
/**
3
 * @package		fwolflib
4
 * @copyright	Copyright 2006, Fwolf
5
 * @author		Fwolf, [email protected]
6
 * @since		2006-07-08
7
 * @version		$Id$
8
 */
9
10
11
require_once(dirname(__FILE__) . '/../fwolflib.php');
12
13
14
/**
15
 * 向数据库中写入数据
16
 * 根据指定的主键或联合主键自动判断是insert还是update
17
 * 当然主键必须有值包含在数据中
18
 *
19
 * @param	object	$db		ADOdb数据库连接对象
20
 * @param	string	$tbl	写入数据表名
21
 * @param	array	$data	要写入的数据,数组array(column=>value,...)形式
22
 * @param	mixed	$pkey	主键,可以是字符串或数组(也可以是定位数据的其他条件,但要求键和值必须包含在data数组中
23
 * @return	mixed			出错返回错误信息,成功返回1(即处理的行数)
24
 */
25
function DbWrite($db, $tbl, $data, $pkey)
26
{
27
	//对要写入数据库的内容进行处理,主要是根据字段类型添加引号
28
	//:TODO:改用缓存机制
29
	$col = $db->MetaColumns($tbl);
30
	foreach ($data as $key => $val)
31
	{
32
		if (isset($col[strtoupper($key)]))
33
		{
34
			//根据字段类型添加引号
35
			if (!in_array($col[strtoupper($key)]->type, array('int', 'integer', 'tinyint', 'decimal', 'bolean', 'numeric')))
36
				$data[$key] = "'" . addslashes($val) . "'";
37
		}
38
		else
39
		{
40
			return("Column $key is not found in db schema.");
41
		}
42
	}
43
	//检查要写入的数据是否存在 insert or update?
44
	$sql = "select count(1) as c from $tbl where 1=1 ";
45
	if (is_array($pkey))
46
	{
47
		//多个值的定位
48
		//$s_pkey will be used again when actually write to db
49
		$s_pkey = '';
50
		foreach ($pkey as $key)
51
		{
52
			//检查键值是否被指定,如果没有被指定,中止操作
53
			if (isset($data[$key]))
54
				$s_pkey .= " and $key = $data[$key] ";
55
			else
56
			{
57
				return("Key $key has not assigned a value.");
58
			}
59
		}
60
		$sql .= $s_pkey;
61
	}
62
	else
63
	{
64
		//单个键值
65
		$s_pkey = " and $pkey = $data[$pkey] ";
66
		$sql .= $s_pkey;
67
	}
68
	$rs = $db->Execute($sql);
69
	$i = $rs->fields['c'];
70
	if (0 == $i)
71
	{
72
		//its insert
73
		$sql = "insert into $tbl (";
74
		//keys
75
		foreach ($data as $key=>$val)
76
		{
77
			$sql .= "$key, ";
78
		}
79
		$sql = substr($sql, 0, strlen($sql) - 2);
80
		$sql .= ") values (";
81
		//values
82
		foreach ($data as $key=>$val)
83
		{
84
			$sql .= "$val, ";
85
		}
86
		$sql = substr($sql, 0, strlen($sql) - 2);
87
		$sql .= ")";
88
	}
89
	elseif (1 == $i)
90
	{
91
		//its update
92
		$sql = "update $tbl set ";
93
		foreach ($data as $key=>$val)
94
		{
95
			$sql .= "$key = $val, ";
96
		}
97
		$sql = substr($sql, 0, strlen($sql) - 2);
98
		$sql .= " where 1=1 ";
99
		//use pkey to locate data
100
		$sql .= $s_pkey;
101
	}
102
	else
103
	{
104
		//got too many match rows
105
		return("Got >1 rows by given pkey, which to update ?");
106
	}
107
	//finally, write to database
108
	//$db->debug = true;
109
	$rs = $db->Execute($sql);
0 ignored issues
show
$rs is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
110
	$i = $db->ErrorNo();
111
	if (0 == $i)
112
	{
113
		//no error
114
		//echo("1 row writed to database, no error.<br />\n");
115
		return 1;
116
	}
117
	else
118
	{
119
		//error occur
120
		return($db->ErrorMsg());
121
	}
122
} // end of function DbWrite
123
124
?>
0 ignored issues
show
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
125