PHP intval function Security Application Tips _php Tutorial

Source: Internet
Author: User
We learn

First, PHP intval function description

The Intval function has a feature: "Until a number or sign is encountered to start the conversion, and then the non-numeric or end of the string () end Conversion", in some applications due to the Intval function This feature is not known enough, the use of errors caused by bypassing some security decisions lead to security vulnerabilities.

Second, PHP intval function analysis

    1. Php_function (Intval)
    2. {
    3. Zval **num, **arg_base;
    4. int base;
    5. Switch (Zend_num_args ()) {
    6. Case 1:
    7. if (ZEND_GET_PARAMETERS_EX (1, &num) = = FAILURE) {
    8. Wrong_param_count;
    9. }
    10. Base = Ten ;
    11. Break

When the Intval function accepts that the string parameter is called convert_to_long_base () processing, the next call is Z_lval_p (OP) = Strtol (Strval, NULL, Base), and the parameter is handled by the Strtol function.

The PHP intval function is prototyped as follows:

Long int strtol (const char *nptr,char **endptr,int base);

This function converts the parameter nptr string based on the parameter base to the number of growth integers, the parameter base range from 2 to 36, or 0. The parameter base represents the input method used, such as the base value of 10 is 10, if the base value of 16 is used 16.

The process is:

Strtol () scans the parameter nptr string, skips the preceding space character until a number or sign is encountered, and then ends the conversion with a non-numeric or string end () and returns the result.

Then when the intval is used in the judgment of if and so on, it will cause this judgment to be meaningful, leading to a security breach.

Third, PHP intval function test code

 
  
  
  1. intval.php
  2. $ var = "20070601" ;
  3. if (Intval ($var))
  4. echo "It ' s safe";
  5. Echo ' $ var = '. $var;
  6. echo "
  7. ";
  8. $ var1 = "1 Union Select 1,1,1 from admin" ;
  9. if (Intval ($var 1))
  10. echo "It ' s safe too";
  11. Echo ' $ var1 = '. $var 1;
  12. ?>

Four, PHP intval function Practical application

WordPress <= 2.0.6 wp-trackback.php zend_hash_del_key_or_index/sql injection Exploit


http://www.bkjia.com/PHPjc/446049.html www.bkjia.com true http://www.bkjia.com/PHPjc/446049.html techarticle we learn one, PHP intval function describes the Intval function has a feature: until the number or sign to start the conversion, and then encountered a non-numeric or string end () end of the conversion, in some ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.