This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: va_list and x86_64 possible bug (?)


On 10/17/07, Macy Gasp <macygasp@gmail.com> wrote:
> Hi everybody,
>
> I'm experiencing a weird behaviour when using va_list with gcc 4.1.2
> on a x86_64 linux distribution.
>
> Below is my test program (yes, I know about the possible buffer
> overflows but please, bear with me, this is just a proof of concept):
>
> #include <stdio.h>
> #include <stdarg.h>
>
> int var(const char* fmt, ...)
> {
>     va_list args;
>     char buf[4096];
>
>     va_start(args, fmt);
>

--- no va_copy

>     vsprintf(buf, fmt, args);
>     fprintf(stderr,"\n[%s]", buf);
>
-- args is semi invalid here.

>     vsprintf(buf, fmt, args);
>     fprintf(stderr,"\n[%s]", buf);
>
>     va_end(args);
>
>     return 0;
> }

You forgot to call va_copy.

-- Pinski


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]