Unix Technical Forum

Re: sprintf warning in libstdc++

This is a discussion on Re: sprintf warning in libstdc++ within the lucky.openbsd.tech forums, part of the OpenBSD category; --> Hello! No need to go ballistic about my mail. On Mon, Mar 14, 2005 at 02:10:05PM -0700, Theo de ...


Go Back   Unix Technical Forum > Unix Operating Systems > OpenBSD > lucky.openbsd.tech

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-22-2008, 12:19 PM
Hannah Schroeter
 
Posts: n/a
Default Re: sprintf warning in libstdc++

Hello!

No need to go ballistic about my mail.

On Mon, Mar 14, 2005 at 02:10:05PM -0700, Theo de Raadt wrote:
>libc is now compiled to warn about such things.


Yeah, I'm aware of that, I'm no newbie, but a software developer myself.

>Yes, there is a library like that included in OpenBSD, used by a few
>rare applications here and there..


>You may have heard of sprintf being associated with buffer overflows
>over the last, oh, what, 10 or more years?


And yeah, I have heard that. I'm fond of the ways OpenBSD uses to defend
against bugs like that, using multiple lines of defence (propolice, W^X
including a non-exec stack, randomized library load addresses, etc.),
and I'm very okay with this warning too (eliminated 2 sprintf
occurrences in own code too, they were non-critical, but easy to
replace, was things like char buf[4]; sprintf(buf, "%02x", ...),
replaced by the obvious snprintf(buf, sizeof(buf), "%02x", ...)).

So no need to defend against a non-existant criticism.

>In this case, it's not really our problem. Go do a ports tree compile.


>Please alert the GNU people about this problem in their code.


It's OpenBSD's copy of GNU code in this case (libstdc++ in OpenBSD's
source tree). I didn't refer to any ports.

>From now on, including OpenBSD 3.7, we will warn for such bad functions
>being called.


Which is a good thing.

>But it is up to the individual outside-source groups to clean their own
>code up.


>So mail them.


I think this case is a bit difficult. As I wrote in my original mail,
there *is* a snprintf variant in that libstdc++ code. It's just the
"configuration" of libstdc++ which assumes (wrongly, of course) that
OpenBSD had no snprintf and falls back to sprintf. That's probably
because it links usage of snprintf and usage of other C99 stuff (if I
believe the name of the preprocessor define which is tested for).

If I had known an easy and clean way to fix it, I'd have suggested a
diff for
/usr/src/gnu/lib/libstdc++/libstdc++/config/locale/{gnu,generic}/c_locale.h

I'm leaving parts of the original mail intact so you can see the
important parts.

>> After checking, it looks like something in libstdc++ really uses
>> sprintf:


>> $ nm /usr/lib/libstdc++.so.34.0 |grep sprintf
>> U sprintf


See, base, not ports!

>> This is i386, current as of last week (Mar 9).


>> Looks like either
>> src/gnu/lib/libstdc++/libstdc++/config/locale/generic/c_locale.h
>> or
>> src/gnu/lib/libstdc++/libstdc++/config/locale/gnu/c_locale.h
>> is the culprit. There's snprintf based replacement code there, but this
>> is conditionalized with #ifdef _GLIBCPP_USE_C99, which seems to be off
>> for OpenBSD.


>> I've seen no change to that code since the last upgrade (just ran cvsync
>> and cvs -nq up -A to check).


Kind regards,

Hannah.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:53 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com