Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Jun 2008
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    null byte in string causing $_GET to be empty

    i have a string - LŔH≤rš‚G3¬d\0(anBž

    this is supposed to be coming from a $_GET variable, called $_GET['info_hash']

    however, the null byte "\0" in this string is causing php to read the variable as empty, as using the empty function tells me it is empty even though it is not.

    what is the workaround for this?

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Escape the backslash, or use strlen() to check the variable, or use if ($val > "")

  • #3
    New Coder
    Join Date
    Jun 2008
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually, I am trying to get the following value via get: "'L%d9H%b2r%e4%e2G3%c2d%05%00%11%28anB%06%ec'"

    That is what shows up in my access logs. I am trying to $_GET that value. PHP seems to think that this value is completely empty if it has "%00" (a null byte) in it.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Try serializing it before sending it. Null bytes I've only seen handled in PHP with binary based data, which isn't really a string to start with. Retrieve it then from you're get, and unserialize the data. Try that, see if that works.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #5
    New Coder
    Join Date
    Jun 2008
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    Try serializing it before sending it. Null bytes I've only seen handled in PHP with binary based data, which isn't really a string to start with. Retrieve it then from you're get, and unserialize the data. Try that, see if that works.
    I can not serialize it before sending it. It gets sent via utorrent to a php file set as the announce URL.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    I do not believe there is another solution with GET if you can't control the transmission. I'll take a look around and see, you may be able to do this with a different type of protocol or transmission method.

    Lets see, if you have a string, which is technically just a null delimited char array, then you should at least be getting the first part of the string, and the remainder lost. I'll try to come up with an example that I can test this with. My suspision is that you should have the first half of that string up to and including the \0 should exist.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •