I personally would not consider this case to be a "sign of a deeper/more pervasive problem" -- definitely not something I'd lose sleep over. Having looked at the faulty (s)printf usage in webmin/miniserv.pl code, I'd expect that most people don't use (s)printf that way.

The whole point of (s)printf is to parameterize the format string, using "%..." placeholders in much the same way that we use "?" placeholders in the sql statements that we execute via DBI. It's kind of surprising (indeed, I am shocked -- shocked!) to see code where scalar variables holding "printable" values are being used directly within the format string, instead of being passed as parameters that will fill the "%..." placeholders that should have been in the format string in the first place.

Looking at the patches for fixing the hole, doing it right is a simple enough habit to get into, and people who read and understand the man page for sprintf generally start out with the correct habits from the start.

(Having said that, however, I can confess that I have caught myself a few times, putting scalar variables into the quoted format string that I pass to sprintf, just because I didn't need a specific column width or leading zeros or fixed decimal point, etc. And of course, if people start getting into "in-line creation" of the format string, by concatenating pieces together, I can imagine that they might lose sight of where placeholders should go, instead of variables -- it's a matter of getting to be a bit too clever at times.)

If you want to be really careful, grep for /s?printf/ in the suspect source code, and look for scalar variables inside double quotes adjacent to those calls. It shouldn't be too hard to cook up a simple perl script to look for potentially offending patterns in perl code -- good enough to catch most cases.

(Yes, yes, yes, it's true that only perl can parse perl source code -- but if a regex and Text::Balanced can spot even one suspect sprintf call in a perl file, you at least know to pay closer attention to that file, and maybe anything by that author.)

updated to fix a grammar mistake; also, checked the perlsec man page, and can report that (s)printf is not mentioned there. Taint mode does not trap tainted data being included as part of the format string passed to (s)printf -- i.e. the following does not die with a taint error, and it does generate a 50K string of spaces:

perl -T -e '$arg = shift; printf "you said $arg\n"' %50000s

In reply to Re: Format string vulnerability by graff
in thread Format string vulnerability by Mr_Person

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.