Skip to content

Commit

Permalink
Fix for DoS/overflow for long file extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
doyler committed Jun 16, 2015
1 parent 5cf6b6c commit 36776d7
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions GoHttp.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,18 +276,23 @@ int getHttpVersion(char *input, char *output)
return -1;
}

int GetExtension(char *input, char *output)
int GetExtension(char *input, char *output, int max)
{
int in_position = 0;
int appended_position = 0;
int i = 0;
int count = 0;

for ( ; i < strlen(input); i ++ )
{
if ( in_position == 1 )
{
output[appended_position] = input[i];
appended_position +=1;
if(count < max)
{
output[appended_position] = input[i];
appended_position +=1;
count++;
}
}

if ( input[i] == '.' )
Expand Down Expand Up @@ -348,7 +353,7 @@ int handleHttpGET(char *input)
{
FILE *fp;

if ( GetExtension(filename, extension) == -1 )
if ( GetExtension(filename, extension, 10) == -1 )
{
printf("File extension not existing");

Expand Down Expand Up @@ -727,4 +732,4 @@ int main(int argc, char* argv[])
start();

return 0;
}
}

0 comments on commit 36776d7

Please sign in to comment.