Am I missing anything?

Discussions of secure PHP coding. Security in software is important, so don't be afraid to ask. And when answering: be anal. Nitpick. No security vulnerability is too small.

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Am I missing anything?

Post by alex.barylski »

Code: Select all

$content = strip_tags(trim($content));
      
      $content1 = mysql_real_escape_string(substr($content, 0, 255));
      $content2 = mysql_real_escape_string(substr($content, 256, 511));
I am using two 256 byte blocks inside my table (max size for VARCHAR???)...unless there is a better way - to store 512 bytes? This introduces a potential security problem if anyone figured out the buffer was split on a 256 byte boundry so I escape both...

Can you see anything else wrong with this? Is my math right? :?

Cheers :)
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Use TEXT.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

Isn't that a variable length field though?
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Yeah, but you can always check the length inbound. VARCHAR, technically speaking, is also a variable length field too.
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Max size for varchar is 256 bytes, but since one byte is always reserved for the size of the data in the column, the max storage is 255 bytes. If you're using MySQL >=5, varchars can be defined as greater than 255 and the column will reserve an second byte to hold the length.
Post Reply