【发布时间】:2016-06-04 06:29:45
【问题描述】:
以下程序:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int check_authentication(char *password)
{
int auth_flag = 0;
char password_buffer[16];
strcpy(password_buffer, password);
if(strcmp(password_buffer, "unipi") == 0)
auth_flag = 1;
if(strcmp(password_buffer, "SSL") == 0)
auth_flag = 1;
return auth_flag;
}
int main(int argc, char *argv[]) {
if(argc < 2) {
printf("Usage: %s <password>\n", argv[0]);
exit(0);
}
if(check_authentication(argv[1])!=0)
{
printf("\n-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
printf(" Access Granted.\n");
printf("-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
}
else
{
printf("\nAccess Denied.\n");
}
}
strcpy(password_buffer, password);这行有一个缓冲区溢出漏洞。如果我们想让这个程序安全而不取出strcpy,这怎么可能?
【问题讨论】:
-
最好的办法是用安全函数替换
strcpy。通过保持strcpy,您希望完成什么? -
“如果我们想让这个程序安全” 针对什么安全?
-
char password_buffer[strlen(password)+1]。欢迎来到堆栈溢出。 -
你为什么要复制
password? -
@Micheal 这超出了这个问题的范围。我只是想尝试使其安全而不删除
strcpy
标签: buffer-overflow c