Anti-armenia.ORG - Forumlar - [C++] Arrays: Buffer Overflow



Istifadəçi
    2012-07-18 18:31 GMT                 

Mr.0c3aN



İstifadəçi
Mesaj Sayı : 144
Mövzu Sayı :
Rep Ver : 
Rep Sayı :   5  
Indi Saytda : Durum
Cinsiyyət : Oğlan
Şəhər : Putnam, Connecticut
Ölkə :
Məslək : System & Algorithmic Programmer, Security Professional
Yaş : 121
Mesaj :

Mövzunu Paylaş!


Because:

Kod:
1. Arrays are fixed size.
2. C++ does not perform subscript range checking.
3. Programmers forget to check bounds, or simply assume nothing can go wrong.
4. Giving a program more data than it can handle is the number one trick in the arsenal of the hacker.


What's wrong with this code?

Kod:
int a[1000];       // Declare an array of 1000 ints
int n = 0;         // number of values in a.
. . .
while (cin >> a[n]) {
    n++;
}


# The additional numbers go somewhere in memory beyond the end of the array! They overwrite whatever was there...


    1. Solution 1 - Check array bounds
    2. Solution 2 - vectors - the correct solution


Solution 1 Explanation:


The following solution prevents subscript bounds violations, by terminating the input after 1000 input numbers without comment.

Kod:
int a[1000];       // Declare an array of 1000 ints
int n = 0;         // number of values in a.
. . .
while (n < 1000 && cin >> a[n]) {
    n++;
}



It would be much better to give an error message, otherwise the user will not realize the results from the program are incorrect. An improvement would be.
int temp;

Kod:
while (cin >> temp) {
    if (n < 1000) {
        a[n] = temp;
        n++;
    } else {
        cerr << "ERROR: More than 1000 number input" << endl;
        exit(1);
    }
}

This still has problems. if we're using a GUI, we can't write to cerr. The solution to that is to throw an exception, but that example will have to wait.

Solution 2 Explanation:


Vectors (from the Standard Template Library) are an expandable array. Google Example - Vector - reverse input example for a solution to the above problems.

Anti-armenia.ORG
    

Istifadəçi
    2012-07-20 00:18 GMT                 

Avatar Fearless



VIP
Mesaj Sayı : 1299
Mövzu Sayı :
Rep Ver : 
Rep Sayı :   23  
Indi Saytda : Durum
Cinsiyyət : Oğlan
Şəhər : Gävle
Ölkə :
Məslək : Hacker,Defacer,Programmer
Yaş : 26
Mesaj :

Mövzunu Paylaş!


Respect + Təşəkkürlər Gözəl Source + Anlatımdı. Hələki BoF olması.

http://s017.radikal.ru/i404/1202/c6/a2947080a3c4.png
Anti-armenia.ORG
    

Istifadəçi
    2012-07-20 07:32 GMT                 

Mr.0c3aN



İstifadəçi
Mesaj Sayı : 144
Mövzu Sayı :
Rep Ver : 
Rep Sayı :   5  
Indi Saytda : Durum
Cinsiyyət : Oğlan
Şəhər : Putnam, Connecticut
Ölkə :
Məslək : System & Algorithmic Programmer, Security Professional
Yaş : 121
Mesaj :

Mövzunu Paylaş!


Təşəkkürlər

Anti-armenia.ORG
    

Istifadəçi
    2013-07-20 16:08 GMT                 

0-dayz



Gold
Mesaj Sayı : 43
Mövzu Sayı :
Rep Ver : 
Rep Sayı :   1  
Indi Saytda : Durum
Cinsiyyət : Oğlan
Şəhər :
Ölkə :
Məslək :
Yaş :
Mesaj :

Mövzunu Paylaş!


Information, which is not enough to prevent overflow in the case of a number of techniques (DEP, StackShield, Stack Cookies, StackGuard, ASLR)

Anti-armenia.ORG
    

Istifadəçi
    2013-07-24 13:05 GMT                 

bill



İstifadəçi
Mesaj Sayı : 269
Mövzu Sayı :
Rep Ver : 
Rep Sayı :   0  
Indi Saytda : Durum
Cinsiyyət : Oğlan
Şəhər :
Ölkə :
Məslək : bill
Yaş :
Mesaj :

Mövzunu Paylaş!


Təşəkkürlər

Anti-armenia.ORG
    

Istifadəçi
    2013-07-25 00:33 GMT                 

Mr.0c3aN



İstifadəçi
Mesaj Sayı : 144
Mövzu Sayı :
Rep Ver : 
Rep Sayı :   5  
Indi Saytda : Durum
Cinsiyyət : Oğlan
Şəhər : Putnam, Connecticut
Ölkə :
Məslək : System & Algorithmic Programmer, Security Professional
Yaş : 121
Mesaj :

Mövzunu Paylaş!


Sitat
#26429 repeat :
Information, which is not enough to prevent overflow in the case of a number of techniques (DEP, StackShield, Stack Cookies, StackGuard, ASLR)



Hey, I apologize about any missing data or information in this post. But the way you expand and share your needs is not fair enough to read and process with awkward silence. Please if you have any needs PM me

Anti-armenia.ORG
    

Istifadəçi
    2013-07-25 13:57 GMT                 

0-dayz



Gold
Mesaj Sayı : 43
Mövzu Sayı :
Rep Ver : 
Rep Sayı :   1  
Indi Saytda : Durum
Cinsiyyət : Oğlan
Şəhər :
Ölkə :
Məslək :
Yaş :
Mesaj :

Mövzunu Paylaş!


No problem my friend, let's talk PM

Anti-armenia.ORG