prevent cat-0 from being tampered with
This commit is contained in:
parent
ea2de810ac
commit
8dfa99d8c6
@ -48,9 +48,19 @@
|
||||
$str = stripslashes( trim( @$_POST['content'] ) ) ;
|
||||
|
||||
if ($str) {
|
||||
$success = io_write_file(CONTENT_DIR . 'categories.txt', $str);
|
||||
entry_categories_encode();
|
||||
$this->smarty->assign('success', ( $success )? 1 : -1 );
|
||||
//$success = io_write_file(CONTENT_DIR . 'categories.txt', $str);
|
||||
$success = entry_categories_encode($str);
|
||||
|
||||
$ret = 1 ;
|
||||
if ($success <= 0) {
|
||||
if ($success == -1) $ret = -3;
|
||||
elseif ($success == 0) $ret = -1;
|
||||
} else {
|
||||
$success = io_write_file(CONTENT_DIR . 'categories.txt', $str) ? -1 : 1;
|
||||
}
|
||||
|
||||
$this->smarty->assign('success', $ret);
|
||||
|
||||
} else {
|
||||
$this->smarty->assign('success', -1 );
|
||||
}
|
||||
|
@ -498,10 +498,11 @@
|
||||
}
|
||||
|
||||
|
||||
function entry_categories_encode() {
|
||||
function entry_categories_encode($cat_file) {
|
||||
|
||||
if ($string = io_load_file(CONTENT_DIR . 'categories.txt')) {
|
||||
$lines = explode("\n", trim($string));
|
||||
|
||||
//if ($string = io_load_file(CONTENT_DIR . 'categories.txt')) {
|
||||
$lines = explode("\n", trim($cat_file));
|
||||
$idstack = $result = $indentstack=array();
|
||||
|
||||
while (!empty($lines)) {
|
||||
@ -519,6 +520,12 @@
|
||||
|
||||
$id = trim($val[1]);
|
||||
$label = trim($val[0]);
|
||||
|
||||
// IDs must be strictly positive
|
||||
|
||||
if ($label && $id <= 0) return -1;
|
||||
|
||||
|
||||
|
||||
if (empty($indentstack)) {
|
||||
array_push($indentstack,$indent);
|
||||
@ -554,7 +561,7 @@
|
||||
|
||||
return io_write_file(CONTENT_DIR . 'categories_encoded.dat', serialize($result));
|
||||
|
||||
}
|
||||
//}
|
||||
|
||||
return false;
|
||||
|
||||
|
@ -175,6 +175,7 @@ Technology :6
|
||||
-1 => 'An error occurred while trying to save categories',
|
||||
2 => 'Categories cleared',
|
||||
-2 => 'An error occurred while trying to clear categories',
|
||||
-3 => 'Category IDs must be strictly positive (0 is not allowed)'
|
||||
|
||||
);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user