Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

155
Views
Format String Attack?

A recent security notice (http://osdir.com/ml/bugtraq.security/2015-04/msg00102.html) stated that this line of code:

fprintf(stderr, (isprint(adata->contents[i])) ? "%c " : "%02x", adata->contents[i]);

was subject to a "format string attack" which I understand as using something like:

fprintf(stderr, varWithUserSuppliedData);

instead of:

fprintf(stderr, "%s", varWithUserSuppliedData);

but I'm not seeing that in that first fprintf call - what am I missing?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Thanks to @cremno for providing a link to the GIT repository for the file in question: kssl.c (Note that this is not the repository head.)

It's clear that this report is spurious. First, there is no real problem with the fprintf call, although you can argue that code in a security-related product like OpenSSL needs to go beyond being secure to the point of being visibly secure even to a casual glance. (I'm not sure I would make that argument, but it has been made.)

But more importantly, the code in question is disabled (note the preprocessor directives surrounding it):

# if 0
{
    int i;
    fprintf(stderr, "%s[at%d:%d] ", label, adata->ad_type, adata->length);
    for (i = 0; i < adata->length; i++) {
        fprintf(stderr, (isprint(adata->contents[i])) ? "%c " : "%02x",
                        adata->contents[i]);
    }
    fprintf(stderr, "\n");
}
# endif
over 4 years ago · Santiago Trujillo Report

0

This looks like an automatically generated error message. Obviously the tool doesn't know which format string will be used, so it cannot analyse the format string and the arguments and declare that the usage is safe.

A more clever tool might figure out that there are just two possibilities for the format string, and that each possibility is safe, and not give an error message.

The code itself is safe. Of course you get rid of the message by using an if/else statement. And in safety critical code, you wouldn't just fix things that are wrong, but also things that look wrong. And you never know, after turning the fprintf into an if/else, the tool might detect a real problem that we all missed.

over 4 years ago · Santiago Trujillo Report

0

Credit must go to rici, but everything looks ok with the code.

Even there is a problem, everything can be printed safe as char or as hex.

Probably the problem could be with the for or while loop that operates over the string.

Could you post the loop as well?

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!