Hmmm… This exactly the kindof reason why i just spent a day finding a reliable way of sanitising printf style format strings in my sql library.
First you parse the format string, identify all the arguments, then call your vsnprintf with chunks of the format string, making sure that the %s arguments are reprocessed to escape nasty things, and increment the va pointer between calls using types inferred from the format string.
Hmmm… This exactly the kindof reason why i just spent a day finding a reliable way of sanitising printf style format strings in my sql library.
First you parse the format string, identify all the arguments, then call your vsnprintf with chunks of the format string, making sure that the %s arguments are reprocessed to escape nasty things, and increment the va pointer between calls using types inferred from the format string.
Works like a charm, may contain traces of nuts.