Thursday, August 13, 2009

Creating a Splash Page in WordPress

Earlier this week one of my clients asked me for help on creating a splash page for a blog they where setting up. I of course said sure and figured it would only take like 2 minutes. Sadly, that wasn't the case there where a few issues that we ran into:
1) The way the blog was setup the urls looked like /?cat=16 instead of url-friendly
2) There was no way to specify a default blog page
3) The client didn't want to move the blog to a sub-folder (understandably)

The first solution I had was to set the default page but without modifying WordPress itself some of the links would just return you to the splash page. After a bit of messing around with .htaccess I finally came up with these two lines of code:


RewriteCond %{QUERY_STRING} !.
RewriteRule ^$ /splash.php


Basically what it says is if there is no querystring specified and the url is an empty string go to the splash screen. That is it and it worked!

Labels: ,

Wednesday, April 30, 2008

Cool Little Code Snippet...

At my work an email sometimes gets sent out asking us to spot the defect.  I like these emails as it is usually with code / bugs that I have no f'ing experience and I can learn something that is a nice little trick.  So enough rambling here is some code that basically has the same bug.


Note: This is a technical post so if you don't care about this geeky crap just stop reading now :).


Disclaimer: I wrote the below code in blogger so it might not compile but the part that is interesting is technically correct.



<codesnippet>  

#include
using namespace std;
int main() {
char * c;
char * junkVar;
  const char * f00;
  junkVar = new char('a');
  f00 = junkVar + 1; 
  c = junkVar + 2;
  if(foo - c >= sizeof(int)) {
    cout << "inside of if-statement" << endl;
  } else {
    cout << "hit else statement instead" << endl;  
}
  return 0;
}

</codesnippet>

So, where is the bug?  How will this code execute if it was ran?  If you look at the code you will notice that "foo - c" should have a difference of -1 since "c" is one higher than "foo".  However, sizeof returns an unsigned integer and the compiler will cast the subtraction operation to an unsigned value as well.  What does that mean?  It means -1 becomes FFFFFFFF which is way bigger than "sizeof(int)" and the if condition would be correct.  Pretty cool, eh?  How would you fix this?  Well just cast the return value of sizeof to something signed like say..int.


There are a few security implications of this code.  Mainly if you could make this happen the pre-conditions of the code executed in the if-statement might not be correct and all sorts of weird issues could crop up.


Alright, back to work...


Labels: , ,