Accept only whole numbers for start and show, and cap show at 50.
This commit is contained in:
+20
-15
@@ -292,29 +292,34 @@ function get_sort_arg() {
|
|||||||
return $sort;
|
return $sort;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_show_num() {
|
// The most stories that one page can show
|
||||||
global $db, $num_stories;
|
define('MAX_SHOW', 50);
|
||||||
$show = NULL;
|
|
||||||
if (isset($_GET['show']) && is_string($_GET['show'])) {
|
// Return a whole number from the query string, limited to $min..$max,
|
||||||
$show = $db->real_escape_string($_GET['show']);
|
// or NULL if the value is missing or is not a whole number
|
||||||
|
function get_int_arg($name, $min, $max = PHP_INT_MAX) {
|
||||||
|
if (!isset($_GET[$name]) || !is_string($_GET[$name]))
|
||||||
|
return NULL;
|
||||||
|
$value = filter_var(trim($_GET[$name]), FILTER_VALIDATE_INT);
|
||||||
|
if ($value === FALSE)
|
||||||
|
return NULL;
|
||||||
|
return max($min, min($max, $value));
|
||||||
}
|
}
|
||||||
if (is_numeric($show))
|
|
||||||
|
function get_show_num() {
|
||||||
|
global $num_stories;
|
||||||
|
$show = get_int_arg('show', 1, MAX_SHOW);
|
||||||
|
if ($show !== NULL)
|
||||||
return $show;
|
return $show;
|
||||||
else if ($num_stories)
|
else if ($num_stories)
|
||||||
return $num_stories;
|
return (int)$num_stories;
|
||||||
else // provide fallback
|
else // provide fallback
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_start_num() {
|
function get_start_num() {
|
||||||
global $db;
|
$start = get_int_arg('start', 0);
|
||||||
$start = NULL;
|
return $start === NULL ? 0 : $start;
|
||||||
if (isset($_GET['start']) && is_string($_GET['start'])) {
|
|
||||||
$start = $db->real_escape_string($_GET['start']);
|
|
||||||
}
|
|
||||||
if (!is_numeric($start))
|
|
||||||
$start = 0;
|
|
||||||
return $start;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user