How to resolve error message generated by Getsqlvaluestring function

Asked

Viewed 110 times

1

I’m using the function GetSQLValueStringof dreamweaverto validate some variables and everything works well, but doing a test with the program Acunetix Web Vulnerability Scanner 9.5 I came across an error message provided by him, accusing a possible security breach. The url generated by the program and the message is this:

http://meusite.com.br/cidades.ajax.php?ajax=true&search=&uf[]=27

PHP Warning: mysql_real_escape_string() expects Parameter 1 to be string, array Given in E: home topdeia Web n-chipi cidades.ajax.php on line 22

That’s the job of:

    if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);     

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
} 

The question is, is there any way around that mistake?

  • Always is a Uf only?

  • Hello @rray, yes, it will always be one UF at a time, in this case the UF is being invoked by clicking on an area of a map for display of representatives.

1 answer

2


WARNING: The functions mysql_* should not be used.

The problem is that the function expects a scalar value but an array has been passed as argument, which gives the hint is the query string (&uf[]=27).

First you need to decide if an array will abort the process and return an error message to the user or take the first element of the array and use?

For the second case as only one Uf must be sent at a time can use the function reset() to put the array pointer in the first position and take its value.

$theValue = is_array($theValue) ? reset($theValue) :  $theValue; //linha adicionada

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);     
  • Thanks for the great help @rray, problem solved.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.