Created
January 22, 2024 19:28
-
-
Save moyix/5eb5ee5f2e1565f6915d8412db347276 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Given the following program: | |
``` | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define BUFFERSIZE 200 | |
#define TRUE 1 | |
#define FALSE 0 | |
int copy_it( char * input ) | |
{ | |
char localbuf[ BUFFERSIZE ]; | |
char c, *p = input, *d = &localbuf[0]; | |
char *upperlimit = &localbuf[ BUFFERSIZE-10 ]; | |
int quotation = FALSE; | |
int roundquote = FALSE; | |
memset( localbuf, 0, BUFFERSIZE ); | |
while( (c = *p++) != '\0' ){ | |
if(( c == '<' ) && (!quotation)){ | |
quotation = TRUE; | |
upperlimit--;} | |
if(( c == '>' ) && (quotation)){ | |
quotation = FALSE; | |
upperlimit++;} | |
if(( c == '(' ) && ( !quotation ) && !roundquote){ | |
roundquote = TRUE;} | |
if(( c == ')' ) && ( !quotation ) && roundquote){ | |
roundquote = FALSE; | |
upperlimit++;} | |
// If there is sufficient space in the buffer, write the character. | |
if( d < upperlimit ) | |
*d++ = c; | |
} | |
if( roundquote ) | |
*d++ = ')'; | |
if( quotation ) | |
*d++ = '>'; | |
printf("%d: %s\n", (int)strlen(localbuf), localbuf); | |
} | |
int main( int argc, char **argv ){ | |
if( argc > 1 ) | |
copy_it( argv[1] ); | |
else | |
printf("Please supply a command line argument.\n"); | |
} | |
``` | |
What input string will trigger a buffer overflow? You may only choose *one* option. | |
A: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA | |
B: ()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()( | |
C: <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>< | |
D: (((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((())))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) | |
Explain your reasoning first, and then give the answer. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment