Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
/* vul_prog. */
#include <stdlib.h>
#include <cstdlib>
#include <stdio.h>
return 0;
}
Writes the C string pointed by format to the standard output (stdout). If format includes format
specifiers (subsequences beginning with %), the additional arguments following format are
formatted and inserted in the resulting string replacing their respective specifiers.
format
C string that contains the text to be written to stdout. It can optionally contain embedded format
specifiers that are replaced by the values specified in subsequent additional arguments and
formatted as requested.
A format specifier follows this prototype: %[flags][width][. precision][length]specifier
Where the specifier character at the end is the most significant component, since it defines the type
and the interpretation of its corresponding argument: (some/common)
parameter meaning passed as
%d decimal (int) value
%u unsigned decimal (unsigned int) value
%x hexadecimal (unsigned int) value
%s string ((const) (unsigned) char*) reference
%n number of bytes written so far, (* int) reference
/* vul_prog. */
#include <stdlib.h>
#include <cstdlib>
#include <stdio.h>
printf("Id : %d ",id);
printf("\n");
printf("Name : %s ", name);
printf("\n");
printf("Age : %d ", age);
return 0;
}
Missing Argument
int main(int argc, char *argv[])
{
int id = 1000, age = 25;
char *name = "Johnny Bravo";
printf("Id : %d ",id);
printf("\n");
printf("Name : %s "); //this will cause an error, because it is null and cannot
print an address from memory/stack
printf("\n");
printf("Age : %d", age);
return 0;
}
Crashing A Program
A crash can happen when %s tried to read from unauthorized memory address.
In computing, a segmentation fault or access violation is a fault, or failure condition, raised by
hardware with memory protection, notifying an operating system the software has attempted to
access a restricted area of memory.