User Tools

Site Tools


ja:rule:num:外部入力の整数データを無闇にキャストしない

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
ja:rule:num:外部入力の整数データを無闇にキャストしない [2016/03/19 02:12] – created yohgakija:rule:num:外部入力の整数データを無闇にキャストしない [2016/03/19 02:15] (current) – [適合コード例 (strpsn)] yohgaki
Line 75: Line 75:
 // There should be arbitrary length limit validation // There should be arbitrary length limit validation
 if (strspn(strlen($_GET['id']) > 100) { if (strspn(strlen($_GET['id']) > 100) {
-  throw new Exception('Invalid integer format');+  throw new Exception('Invalid integer format - too long');
 } }
 // Validate $_GET['id'] contains only 0 to 9 chars and leading +-. // Validate $_GET['id'] contains only 0 to 9 chars and leading +-.
-$start = ($_GET['id']{1} === '+' || $_GET['id'] === '-') ? 1 : 0;+$start = ($_GET['id']{0} === '+' || $_GET['id']{0} === '-') ? 1 : 0;
 if (strspn($_GET['id'], '0123456789', $start) !== strlen($_GET['id']) - $start) { if (strspn($_GET['id'], '0123456789', $start) !== strlen($_GET['id']) - $start) {
   throw new Exception('Invalid integer format');   throw new Exception('Invalid integer format');
Line 84: Line 84:
 </code> </code>
  
-このような単純な文字列チェックには正規表現を避け、文字列関数を使用するべである。+このような単純な文字列チェックには正規表現を避け、文字列関数を使用するべである。
  
 ===== 例外 ===== ===== 例外 =====
ja/rule/num/外部入力の整数データを無闇にキャストしない.1458353568.txt.gz · Last modified: 2016/03/19 02:12 by yohgaki

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki