From e062bda761a21fa33c6977d908ee8112f533f985 Mon Sep 17 00:00:00 2001 From: Chen Ran Date: Mon, 25 Jul 2016 22:39:54 +0800 Subject: [PATCH] Fix server SQLi and XSS and other problems... --- ajax/contest_data.php | 8 ++++---- ajax/contest_status_data.php | 4 ++-- ajax/discuss_data.php | 5 ++--- ajax/mail_data.php | 8 ++++---- ajax/news_data.php | 8 ++++---- ajax/problem_category_data.php | 10 +++++----- ajax/problem_data.php | 6 +++--- ajax/problem_leader.php | 8 ++++---- ajax/ranklist_data.php | 16 ++++++++-------- ajax/status_data.php | 4 ++-- ajax/topic_new.php | 4 ++-- contest.php | 6 +++--- contest_prob.php | 6 +++--- contest_show.php | 4 ++-- contest_status.php | 4 ++-- discuss.php | 2 +- functions/discuss.php | 6 +++--- problem.php | 2 +- problem_category_result.php | 6 +++--- problem_show.php | 4 ++-- problem_stat.php | 3 +-- status.php | 4 ++-- userinfo.php | 4 ++-- 23 files changed, 65 insertions(+), 67 deletions(-) diff --git a/ajax/contest_data.php b/ajax/contest_data.php index 412e6d29..4f33bfc7 100644 --- a/ajax/contest_data.php +++ b/ajax/contest_data.php @@ -10,8 +10,8 @@ $sLimit = ""; if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' ) { - $sLimit = "LIMIT ".convert_str( $_GET['iDisplayStart'] ).", ". - convert_str( $_GET['iDisplayLength'] ); + $sLimit = "LIMIT ".intval( $_GET['iDisplayStart'] ).", ". + intval( $_GET['iDisplayLength'] ); } //ordering @@ -23,10 +23,10 @@ if ( $_GET[ 'bSortable_'.intval($_GET['iSortCol_'.$i]) ] == "true" ) { $sOrder .= $aColumns[ intval( $_GET['iSortCol_'.$i] ) ]." - ".convert_str( $_GET['sSortDir_'.$i] ) .", "; + ".( $_GET['sSortDir_'.$i] == "asc" ? "asc" : "desc") .", "; } } - + $sOrder = substr_replace( $sOrder, "", -2 ); if ( $sOrder == "ORDER BY" ) { diff --git a/ajax/contest_status_data.php b/ajax/contest_status_data.php index 50c36527..01db6206 100644 --- a/ajax/contest_status_data.php +++ b/ajax/contest_status_data.php @@ -15,8 +15,8 @@ $sLimit = ""; if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' ) { - $sLimit = "LIMIT ".convert_str( $_GET['iDisplayStart'] ).", ". - convert_str( $_GET['iDisplayLength'] ); + $sLimit = "LIMIT ".intval( $_GET['iDisplayStart'] ).", ". + intval( $_GET['iDisplayLength'] ); } foreach ((array)contest_get_problem_basic($cid) as $row) { diff --git a/ajax/discuss_data.php b/ajax/discuss_data.php index 9403069c..21219b80 100644 --- a/ajax/discuss_data.php +++ b/ajax/discuss_data.php @@ -1,9 +1,8 @@ match($user)||!$current_user->is_valid()) $sLimit = "LIMIT 0,0"; @@ -24,10 +24,10 @@ if ( $_GET[ 'bSortable_'.intval($_GET['iSortCol_'.$i]) ] == "true" ) { $sOrder .= $aColumns[ intval( $_GET['iSortCol_'.$i] ) ]." - ".convert_str( $_GET['sSortDir_'.$i] ) .", "; + ".( $_GET['sSortDir_'.$i] == "asc" ? "asc" : "desc" ) .", "; } } - + $sOrder = substr_replace( $sOrder, "", -2 ); if ( $sOrder == "ORDER BY" ) { diff --git a/ajax/news_data.php b/ajax/news_data.php index 00ca634f..98719da4 100644 --- a/ajax/news_data.php +++ b/ajax/news_data.php @@ -9,8 +9,8 @@ $sLimit = ""; if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' ) { - $sLimit = "LIMIT ".convert_str( $_GET['iDisplayStart'] ).", ". - convert_str( $_GET['iDisplayLength'] ); + $sLimit = "LIMIT ".intval( $_GET['iDisplayStart'] ).", ". + intval( $_GET['iDisplayLength'] ); } //ordering @@ -22,10 +22,10 @@ if ( $_GET[ 'bSortable_'.intval($_GET['iSortCol_'.$i]) ] == "true" ) { $sOrder .= $aColumns[ intval( $_GET['iSortCol_'.$i] ) ]." - ".convert_str( $_GET['sSortDir_'.$i] ) .", "; + ".( $_GET['sSortDir_'.$i] == "asc" ? "asc" : "desc") .", "; } } - + $sOrder = substr_replace( $sOrder, "", -2 ); if ( $sOrder == "ORDER BY" ) { diff --git a/ajax/problem_category_data.php b/ajax/problem_category_data.php index 3271c761..b13e2264 100644 --- a/ajax/problem_category_data.php +++ b/ajax/problem_category_data.php @@ -25,8 +25,8 @@ $sLimit = ""; if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' ) { - $sLimit = "LIMIT ".convert_str( $_GET['iDisplayStart'] ).", ". - convert_str( $_GET['iDisplayLength'] ); + $sLimit = "LIMIT ".intval( $_GET['iDisplayStart'] ).", ". + intval( $_GET['iDisplayLength'] ); } //ordering @@ -38,10 +38,10 @@ if ( $_GET[ 'bSortable_'.intval($_GET['iSortCol_'.$i]) ] == "true" ) { $sOrder .= $aColumns[ intval( $_GET['iSortCol_'.$i] ) ]." - ".convert_str( $_GET['sSortDir_'.$i] ) .", "; + ".( $_GET['sSortDir_'.$i] == "asc" : "asc" ? "desc") .", "; } } - + $sOrder = substr_replace( $sOrder, "", -2 ); if ( $sOrder == "ORDER BY" ) { @@ -137,7 +137,7 @@ foreach ( (array)$db->get_results( $sQuery,ARRAY_N ) as $aRow ) { - $row = array(); + $row = array(); //var_dump($aRow); for ( $i=0 ; $iget_results( $sQuery,ARRAY_A ) as $aRow ) { $row = array(); - list($rank)=$db->get_row("select count(*)+1 from user where local_ac>".$aRow["local_ac"]." or - (local_ac=".$aRow["local_ac"]." and total_ac>".$aRow["total_ac"].") or - (local_ac=".$aRow["local_ac"]." and total_ac=".$aRow["total_ac"]." and total_submit<".$aRow["total_submit"].") or + list($rank)=$db->get_row("select count(*)+1 from user where local_ac>".$aRow["local_ac"]." or + (local_ac=".$aRow["local_ac"]." and total_ac>".$aRow["total_ac"].") or + (local_ac=".$aRow["local_ac"]." and total_ac=".$aRow["total_ac"]." and total_submit<".$aRow["total_submit"].") or (local_ac=".$aRow["local_ac"]." and total_ac=".$aRow["total_ac"]." and total_submit=".$aRow["total_submit"]." and username<'".$aRow["username"]."' )",ARRAY_N); $row[]=$rank; for ( $i=1 ; $iPrivate - +
@@ -109,9 +109,9 @@ var timezone = jstz.determine_timezone(); $("#localtz").html(timezone.name()+" GMT"+timezone.offset()); $("#tzinp").val(timezone.name()); -var searchstr=''; +var searchstr=; var conperpage=; -var cshowtype=''; +var cshowtype=; $.fn.problemlist.ojoptions=""; diff --git a/contest_prob.php b/contest_prob.php index 42f92a3c..de396d31 100644 --- a/contest_prob.php +++ b/contest_prob.php @@ -33,7 +33,7 @@ } else { ?> get_val('vname'),array('UESTC','HDU'))) { + if (in_array($show_problem->get_val('vname'),array('UESTC','HDU', 'BNU'))) { ?> diff --git a/problem_category_result.php b/problem_category_result.php index d7917a39..7247e409 100644 --- a/problem_category_result.php +++ b/problem_category_result.php @@ -6,7 +6,7 @@ $scate=array(); if (isset($_GET['category'])) { - $catarr='[{"name": "catenum", "value":"1"}, {"name": "logic", "value":"or"}, {"name":"cate0", "value":"'.$_GET['category'].'"}]'; + $catarr='[{"name": "catenum", "value":"1"}, {"name": "logic", "value":"or"}, {"name":"cate0", "value":'.json_encode($_GET['category']).'}]'; $scate[]=htmlspecialchars(problem_get_category_name_from_id(convert_str($_GET['category']))); } else { @@ -15,12 +15,12 @@ $num=0; foreach($_POST as $kkey=>$value) { if ($kkey=="logic") continue; - + $pt=problem_get_category_parent_from_id(convert_str($value)); if (isset($_POST["check".$pt])==$value) continue; $scate[]=htmlspecialchars(problem_get_category_name_from_id(convert_str($value))); - $catarr.=',{"name":"cate'.$num.'", "value":"'.$value.'"}'; + $catarr.=',{"name":"cate'.$num.'", "value":'.json_encode($value).'}'; $num++; } $catarr.=',{"name":"catenum", "value":"'.$num.'"} ]'; diff --git a/problem_show.php b/problem_show.php index 1d816c61..ea2db3a4 100644 --- a/problem_show.php +++ b/problem_show.php @@ -277,8 +277,8 @@ - - + + diff --git a/problem_stat.php b/problem_stat.php index e853e62b..905afee4 100644 --- a/problem_stat.php +++ b/problem_stat.php @@ -1,7 +1,6 @@ set_problem($pid); if ($show_problem->is_valid() && $show_problem->get_val("hide")==0) $pagetitle="Statistics of Problem ".$pid; diff --git a/status.php b/status.php index be34d51a..e11c4e76 100644 --- a/status.php +++ b/status.php @@ -41,8 +41,8 @@ - - + + diff --git a/userinfo.php b/userinfo.php index 0b02e8ae..0e89158d 100644 --- a/userinfo.php +++ b/userinfo.php @@ -1,5 +1,5 @@