Overwriting an uninitialized local variable in PHP



I'm addressing a PHP with a MySQL DB system.

A PHP script looks like this:

$sort_mode = $_GET['sort'];
if($sort_mode = 'ascendend') $query = "....";
else if($sort_mode = 'descendend') $query = "....";
...
mysql_query($query) or die();

This script does actually contain some serious problem because $sort_mode is not sanitized. But this variable is never used in a SQL query, so even if you modify the GET Parameter to become a SQL injection it won't be executed by the DB because this variable is not passed to the engine. The actual variable containing the query is $query. But since there's no else clause, $query is uninitialized, when you pass a string to the variable $sort_mode that is not contained in the if-then-else statement (e.g. $sort_mode = 'does_not_exist')

My question is if there is a way to "initialize" the variable $query myself as an attacker from the outside, so that I can write my on SQL query.

This question is related to a webapp review I'm doing at the moment.

Thx in advance!



Relevant Pages

  • mysql_query strangeness (misreported syntax error?)
    ... I'm attempting to pass a SQL query to a MySQL database through PHP's ... "You have an error in your SQL syntax; ...
    (alt.php)
  • Re: mysql_query(): supplied argument is not a valid MySQL-Link resource
    ... When I had my first attempt at using functions in a PHP script I had similar ... I got round it by passing all variables outside the function into ... > close a connection to the database very time I run a query. ...
    (comp.lang.php)
  • Re: mysql_query return value confusion
    ... Bill wrote: ... > I have the following line in a php script ... query was legal and could be executed by the server. ... When I passed the mysql resource in the mysql_affected_rows(<db resource ...
    (alt.php)
  • Re: SHOW TABLE STATUS
    ... I am using MySQL - 4.1.22 when i use the following sql query ... 1064 Error Message: You have an error in your SQL syntax; ... SHOW TABLE query for version 4.1.22 and also is there a difference ...
    (comp.lang.php)
  • Re: Query problems with PostgreSQL
    ... postgresql database. ... I have a form where I can enter a search query - for instance a last ... 'public.archived_with_photos' is a view defined on the postgresql ... the exact same query failed with the PHP script. ...
    (comp.lang.php)