[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ggi-develop
Subject:    Re: LIBGGI: security patch
From:       Andreas Beck <becka () uni-duesseldorf ! de>
Date:       2002-01-27 18:58:03
[Download RAW message or body]

> > That's the point. I cannot derive from that, if snprintf will
> > terminate the string, if an overflow occurs, without leaving a little
> > doubt. 
> So, the question is, what does vsnprintf() ?

It seems to do the right thing. However I'd vote for testing it at
configure time and complain if it does something else.

Sample test code follows. Anyone who knows how to include that or something 
like it in the configure macros?

CU, Andy

#include <stdio.h>
#include <stdlib.h>

int main(int argc,char *argv[]){

        char test[20];
        int x;

        memset(test,0x42,sizeof(test));
        test[sizeof(test)-1]='\0';

        snprintf(test,10,"%15s","Thisisverystrange");
        for(x=10;x<sizeof(test)-1;x++) {
                if (test[x]!=0x42) {
                        printf("Your snprintf is VERY broken. Byte %d is %02x.\n",x,test[x]);
                        return EXIT_FAILURE;
                }
        }

        if (strcmp(test,"Thisisver")) {
                printf("Your snprintf is broken. Should say Thisisver, says %s.\n",test);
                return EXIT_FAILURE;
        }

        return EXIT_SUCCESS;
}


-- 
= Andreas Beck                    |  Email :  <becka@bedatec.de>             =

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic