Fix buffer overflow due to null character

This commit is contained in:
Eric Chu 2016-04-15 12:54:30 -04:00
parent 615cf81a9f
commit be83d77187

View File

@ -76,14 +76,14 @@ int main(int argc, char **argv)
error(payload, "Pattern not found"); error(payload, "Pattern not found");
} }
u8 input[37] = {0}; u8 input[38] = {0};
u8 payloadname[2 * sizeof(input)] = {0}; u8 payloadname[2 * (sizeof(input) - 1)] = {0};
printf("Enter the payload's path (37 characters max): "); printf("Enter the payload's path (37 characters max): ");
scanf("%37s", input); scanf("%37s", input);
unsigned int i; unsigned int i;
for (i = 0; i < sizeof(input); i++) for (i = 0; i < sizeof(input) - 1; i++)
payloadname[2 * i] = input[i]; payloadname[2 * i] = input[i];
memcpy(found + 12, payloadname, sizeof(payloadname)); memcpy(found + 12, payloadname, sizeof(payloadname));