Skip to content

Commit

Permalink
Merge pull request #150 from bjjwwang/0807
Browse files Browse the repository at this point in the history
Create ExtAPI_strcat 4 cases
  • Loading branch information
yuleisui authored Sep 5, 2024
2 parents a5c7c68 + 70ab0c2 commit 195b127
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/ae_overflow_tests/ExtAPI_strcat_01.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <stdio.h>
#include <string.h>
extern void UNSAFE_BUFACCESS(void *buffer, int size);

int main() {
char buffer[10];
char *largeString = "worldworld";
strcpy(buffer, "Hello");
strcat(buffer, largeString);
UNSAFE_BUFACCESS(buffer, 5 + 10 + 1); // Hello 5, worldworld 10, null terminator 1
return 0;
}
15 changes: 15 additions & 0 deletions src/ae_overflow_tests/ExtAPI_strcat_02.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <stdio.h>
#include <string.h>
extern void UNSAFE_BUFACCESS(void *buffer, int size);
int main() {
char buffer[20] = "";
char *strings[] = {"Hello", "World", "This", "Is", "Too", "Long"};
int i;
for (i = 0; i < 6; i++) {
strcat(buffer, strings[i]);
}
UNSAFE_BUFACCESS(buffer, 23);
printf("Buffer: %s\n", buffer);

return 0;
}
14 changes: 14 additions & 0 deletions src/ae_overflow_tests/ExtAPI_strcat_03.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <stdio.h>
#include <string.h>
extern void UNSAFE_BUFACCESS(void *buffer, int size);

int main() {
char buffer[10] = "Hi";
char input[20];
printf("Enter a string: ");
scanf("%19s", input);
strcat(buffer, input);
UNSAFE_BUFACCESS(buffer, strlen(buffer));
printf("Buffer: %s\n", buffer);
return 0;
}
13 changes: 13 additions & 0 deletions src/ae_overflow_tests/ExtAPI_strcat_04.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <stdio.h>
#include <string.h>
extern void UNSAFE_BUFACCESS(void *buffer, int size);
int main() {
char buffer[15] = "Start";
char *string1 = "12345";
char *string2 = "67890";
strcat(buffer, string1);
strcat(buffer, string2);
UNSAFE_BUFACCESS(buffer, 5 + strlen(string1) + strlen(string2));
printf("Buffer: %s\n", buffer);
return 0;
}

0 comments on commit 195b127

Please sign in to comment.