Re: printf
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Tue, 31 Jul 2007 00:55:02 -0700
Shane <shane@xxxxxxxxxxxxxxxxxxxx> writes:
[...]
Suffice to say I have tried
printf((char *)pointer_to_bin_data);
and
printf((int *)pointer_to_bin_data);
I *hope* that didn't work.
The first argument to printf is a format string (actually a pointer to
a format string). The first call at least passes soething of the
right type, but it's probably going to print whatever
pointer_to_bin_data points to on stdout as raw binary data, up to the
first '\0' character that it happens to see -- but if it happens to
run across a '%' character, it's likely to interpret it as a directive
and try to consume more arguments. Kaboom.
The second call doesn't even pass the correct type. Your compiler
should complain about it; if it doesn't, you probably forgot the
required '#include <stdio.h>'.
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <
http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <
http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.
Relevant Pages
- Re: Secure C library
... > mean that the programmer meant to do that. ... the attacker-supplied format string doesn't cause any of ... While array indices might not be transitory, ... > validate a pointer read in with %p in any meaningful way. ... (comp.std.c) - Re: Stupid? format question
... I'm just curious if Lisp has the ability to embed human-readable control ... I can embed a tab character, ... have multiple sequential tabs, I can't tell in Emacs how many I have by ... of indirection between the format string and the output. ... (comp.lang.lisp) - Re: Pointers and Allocated Memory
... works when I'm lucky enough to have the characters ... assigned to unallocated memory, and it doesn't when I'm not. ... The pointer doesn't necessarily point at anything. ... etc) the format string allows you to limit how many ... (comp.lang.c) - Re: Quines
... Check your compiler documentation for how it's supposed to work. ... The line on which 'c' is initialized is hard to read, the trickiest point is noticing that the second '"' character is escaped, so that it's the third '"' character that actually terminates the string. ... Note that this format string contains 7 '%' characters, each of which starts a format specifier; the other characters in the format string are simply printed as shown. ... I think it will be clearer what is happening if I write 8 printf() statements that will print the same output as the original printf: ... (comp.lang.c) - Re: int to ascii character?
... ascii character into a string append with some other text or values?? ... you should take a look at sprintf() and all its format parameters. ... built the format string for another sprintf function like this one: ... char message; ... (microsoft.public.windowsce.embedded.vc) |
|