...

View Full Version : null byte in string causing $_GET to be empty



DionDev
03-24-2009, 11:24 PM
i have a string - LHrG3d\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?

Fumigator
03-24-2009, 11:30 PM
Escape the backslash, or use strlen() to check the variable, or use if ($val > "")

DionDev
03-25-2009, 04:47 PM
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.

Fou-Lu
03-25-2009, 05:15 PM
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.

DionDev
03-25-2009, 06:21 PM
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.

Fou-Lu
03-25-2009, 06:29 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum