Re: integer to characters

From: Micah Cowan (micah_at_cowan.name)
Date: 10/29/03


Date: 29 Oct 2003 11:41:10 -0800

Gene Wirchenko <gwirchenkoEXCEPT@CAPITALSwencomine.com> writes:

> On Wed, 29 Oct 2003 06:47:39 +0000 (UTC), Richard Heathfield
> <dontmail@address.co.uk.invalid> wrote:
>
> >Alan Kelon wrote:
>
> [snip]
>
> >> Yes, you're correct. Sorry about this, I found this information from my
> >> compiler's help, but I tried to find itoa from The C Programming Language
> >> by K&R and I found this implementation:
> >
> >I don't understand why you need it. What is wrong with:
> >
> >sprintf(s, "%d", i);
> >
> >?
>
> Possible buffer overflow.

Yes, but so did the itoa(). However, sprintf() is defined by the
Standard, itoa() is not.

The buffer-safe version, snprintf(), is not available in C90.

The problem is easily averted by first checking your buffer size
before using sprintf().

-- 
Micah J. Cowan
micah@cowan.name


Relevant Pages

  • Re: snprint rationale?
    ... >Does this mean that your sprintf implementation is broken? ... overrunning the buffer. ... I investigated the stdio implementation ... Trying to write snprintf() using this particular printf engine ...
    (comp.lang.c)
  • Automatic discovery of shellcode address
    ... I've been playing around with LD_PRELOAD under Linux to modify ... some functions commonly susceptible to buffer overflows, strcpy, ... you're overflowing is, (in the case of sprintf, strcpy etc), you ...
    (Vuln-Dev)
  • Re: Access violation at the end of the program
    ... void RetrieveDateTime ... You have a buffer overrun in SetFileName's sprintf, ... Of course, your filename ...
    (microsoft.public.vc.language)
  • Telnet client in C
    ... int main ... sprintf (buffer, "%c%c%c",255,252,36); ... //sending the username ...
    (comp.lang.c)
  • Re: DATETIME like YYYYMMDDHHMMSS
    ... on a limited size buffer and there is no ... > The standard won't change to break old but conforming code. ... > time will break backwards compatibility, than sprintf. ... so this sub-thread hurts me double. ...
    (comp.lang.cpp)