//case 1:
// run: ./a.out 00000000001
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct UserInfo {
char pass[10];
bool check;
};
int main(int argc, char *argv[]) {
if (argc != 2) {
printf("Invalid params\n");
exit(1);
}
UserInfo info;
info.check = false;
memset(info.pass, 0, 10);
strcpy(info.pass, argv[1]);
if (0 == strcmp("shine", info.pass)) {
info.check = true;
}
if (info.check) {
printf("Check password succ!\n");
} else {
printf("Check password failed!\n");
}
return 0;
}
//case 2
#include <iostream>
#include <chrono>
#include <thread>
#include <cstdio>
void Fun() {
for (;;)
{
std::this_thread::sleep_for(std::chrono::milliseconds(300));
std::cout << "Fun" << std::endl;
}
}
int Check() {
long long arr[2] = { 1,2 };
arr[3] = (long long)&Fun;
std::cout << "Check" << std::endl;
return 0;
}
int main()
{
Check();
return 0;
}
备份地址: 【构造缓存区溢出】