Difference between revisions of "Integer Overflows/Underflows"

Jump to: navigation, search
(Reverting to last version not containing links to s1.shard.jp)
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[http://s1.shard.jp/bireba/antivirus-f-prot.html antivirus software for download
] [http://s1.shard.jp/olharder/autoroll-654.html http] [http://s1.shard.jp/olharder/auto-california.html automotive concept design
] [http://s1.shard.jp/galeach/new194.html adventure asia international
] [http://s1.shard.jp/galeach/new155.html imagine asian theatre] [http://s1.shard.jp/olharder/44-auto-trader-nz.html 900 auto part saab
] [http://s1.shard.jp/olharder/autoroll-654.html domain] [http://s1.shard.jp/galeach/new123.html asia tsunami facts and figures
] [http://s1.shard.jp/bireba/airscanner-mobile.html norton antivirus software for free download
] [http://s1.shard.jp/frhorton/3q938n1mz.html wooden african masks
] [http://s1.shard.jp/galeach/new72.html aphasia fluent] [http://s1.shard.jp/olharder/auto-classifieds.html three wheeled automobiles
] [http://s1.shard.jp/olharder/autoroll-654.html top] [http://s1.shard.jp/galeach/new173.html asianspirit philippines
] [http://s1.shard.jp/losaul/the-lakes-golf.html australia rmit university
] [http://s1.shard.jp/olharder/autoroll-654.html domain] [http://s1.shard.jp/frhorton/yoc3js17e.html africa information news travel
] [http://s1.shard.jp/galeach/new148.html euthanasia mercy killing
] [http://s1.shard.jp/galeach/new7.html asian association diabetes
] [http://s1.shard.jp/galeach/new21.html airfare asian discount] [http://s1.shard.jp/olharder/autoroll-654.html http] [http://s1.shard.jp/olharder/rockies-auto-colorado.html renta de automobile
] [http://s1.shard.jp/galeach/new88.html asian crafts for kid
] [http://s1.shard.jp/olharder/autoroll-654.html http] [http://s1.shard.jp/olharder/autoroll-654.html http] [http://s1.shard.jp/galeach/new50.html african and asian elephants
] [http://s1.shard.jp/bireba/norton-antivirus.html nortons antivirus software
] [http://s1.shard.jp/frhorton/o5mgjok5p.html corruption in africa
] [http://s1.shard.jp/galeach/new137.html asiasari
] [http://s1.shard.jp/galeach/new146.html story of anastasia romanov
] [http://s1.shard.jp/frhorton/p7w3g6anv.html the bushmen of africa
] [http://s1.shard.jp/olharder/auto-panel-plus.html automobile accidents by age
] [http://s1.shard.jp/frhorton/4dyaal72j.html sundaytimes south africa
] [http://s1.shard.jp/olharder/autoroll-654.html sitemap] [http://s1.shard.jp/frhorton/3otvgvzdn.html don lino africa cigar
] [http://s1.shard.jp/frhorton/tulkpyc4u.html ngm wildcamafrica.com
] [http://s1.shard.jp/bireba/maafee-antivirus.html nortan antivirus 2005 activation key
] [http://s1.shard.jp/olharder/autoridad-nacional.html autopsy record
] [http://s1.shard.jp/galeach/new13.html mall of asia philippines
] [http://s1.shard.jp/bireba/antiviruscom.html vista antivirus
] [http://s1.shard.jp/frhorton/vjlche4gq.html hsrc south africa
] [http://s1.shard.jp/bireba/etrust-antivirus.html norton antivirus 2005 serial keys
] [http://s1.shard.jp/olharder/o-riley-autoparts.html brad fittler autobiography
] [http://s1.shard.jp/olharder/auto-insurance.html auto insurance louis st] [http://s1.shard.jp/losaul/email-directory.html news sites australia
] [http://s1.shard.jp/olharder/automobile-bmw.html aaa approved auto repair
] [http://s1.shard.jp/olharder/22-auto-barrels.html 22 auto barrels pistol ruger target] [http://s1.shard.jp/losaul/australia-transcriber.html aircraft maintenance training australia

Latest revision as of 06:50, 3 June 2009

This page was marked to be reviewed for deletion.

#REDIRECT Integer_overflow

Last revision: 06/3/2009


Integer overflow belongs to a logic errors family. It occurs when a given range of int (integer) type numbers is overflowed due to arithmetic operations. Generally there are only two operations which cause these kind of errors - addition and multiplication.

Risk Factors



Example 1 (addition)

rezos@bezel ~/labs/integer $ cat add.c
#include <stdio.h>
#include <limits.h>

int main(void)
 int a;

//  a=2147483647;

 printf("int a (INT_MAX) = %d (0x%x), int a (INT_MAX) + 1 = %d (0x%x)\n", a,a,a+1,a+1);

 return 0;

rezos@bezel ~/labs/integer $ ./add
int a (INT_MAX) = 2147483647 (0x7fffffff), int a (INT_MAX) + 1 = -2147483648 (0x80000000)

By adding 1 to the biggest possible signed (+ or -) integer value we overwrite the sign bit. In short, by adding two positive numbers we get one big negative number.

Example 2 (multiplication)

rezos@bezel ~/labs/integer $ cat multiplication.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

int main(int argc, char **argv)
 int i, j, z=0x00000001;
 char *tab;

 if(argc<2) _exit(1);


 if(i>0) {
   tab = malloc(i * sizeof(char *));
   if(tab == NULL) _exit(2);

 for(j=0; j<i; j++)

 for(j=0; j<i; j++)
   printf("tab[j]=0x%x\n", tab[j]);

 return 0;

rezos@bezel ~/labs/integer $ ./multiplication 1073741824
Segmentation fault

The program should write a "z" value into the array of pointers and then print it out. With a specially selected array size (number of its elements) it's possible to use an integer overflow error to overflow the array "tab".

The example below explains why it happens.

rezos@bezel ~/labs/integer $ cat multi.c
#include <stdio.h>

int main(void)
 printf ("1073741824 *4 = %d\n", 1073741824 * 4);
 return 0;

In this program we multiply 1073741824 * 4 because sizeof(char *) will return 4.

rezos@bezel ~/labs/integer $ gcc -ggdb multi.c -o multi
multi.c: In function 'main':
multi.c:6: warning: integer overflow in expression

The compiler warns us that the program contains an expression which causes an integer overflow. To make sure what the result of the multiplication will be:

rezos@bezel ~/labs/integer $ ./multi
1073741824 *4 = 0

malloc(0) (in the main example) will allocate memory with size 0 correctly(poprawnie)/successfully(z powodzeniem), and that will allow for overwriting memory segments on the heap.

Memory allocation with a negative value may cause allocation of very small or very big memory segments depending on the implementation of the *alloc() functions. Integer overflow errors may also lead to the situation where condition statements, which are supposed to check buffers boundaries, are omitted.

Integer overflow errors are not always a threat themselves. However they provide the possibility to overwrite or to read memory content beyond boudries of the buffers, for example during buffer indexing.

Related Threat Agents

Related Attacks

Related Vulnerabilities

Related Controls

  • Use programming language and/or compiler, which will check the buffers boundries and their indexes.
  • Use libraries, which provides API for arithmetic operations (e.g. safe_iop[1], IntegerLib[2])
  • Check results of the arithmetic operations, which used integer numbers and compare them with the expected values.