View Single Post
  #2317  
Old December 2nd, 2008, 07:53 PM
vfb's Avatar

vfb vfb is offline
General
 
Join Date: Mar 2007
Location: Japan
Posts: 3,691
Thanks: 269
Thanked 397 Times in 200 Posts
vfb is on a distinguished road
Default Re: Bug Thread: Discussion

Quote:
Originally Posted by MaxWilson View Post
Oh, wow. %n does not modify the output from printf but instead treats its arguments are a memory address and sets it to the number of characters printed so far. That raises the threat potential from printing out the contents of your Dom3 process to modifying memory, including the instruction pointer. http://julianor.tripod.com/bc/formatstring-1.2.pdf

It's interesting that vfb reports that this will cause crashes. Maybe Dom3 is compiled in a mode that does stricter checking of printf, and throws an exception if the wrong number of arguments is supplied. In that case it's not a security threat after all.

-Max
No, I just said %s will cause crashes. I did not think of %n, I was not aware of that actually.

The printf call used does check for a null argument to %s on the stack and prints "(null)" in that case, but it's going to seg fault (crash) if there's something on the stack like a random integer value.

It's impossible to do a compile-time check of the printf arg count when the format string itself is variable. And that's the problem here, the format string should be "%s" instead of the user-entered message.

It's also impossible for a library function like printf to know how many arguments it was actually passed. Whatever is on the stack is just there, and it will try to use it according to the format string.
__________________
Whether he submitted the post, or whether he did not, made no difference. The Thought Police would get him just the same. He had committed— would still have committed, even if he had never set pen to paper— the essential crime that contained all others in itself. Thoughtcrime, they called it. Thoughtcrime was not a thing that could be concealed forever.
http://z7.invisionfree.com/Dom3mods/index.php?
Reply With Quote