我正在用 C 编写一个简单的程序:
int main(int argc, char** argv) {
unsigned char* line = (unsigned char* ) malloc(0xFFFF);
while (gets(line) > 0) {
if (line[0] == 'l') {
if (line[2]=='.' && line[3] == '.') {
printf("forbidden path");
}
unsigned char* res = (unsigned char* ) malloc(0xFFFF);
unsigned char* cmd = (unsigned char* ) malloc(strlen(line) +
1 + strlen(" | grep -v xml") + strlen("/home/files/"));
strcpy(cmd, "ls ");
strcpy(cmd + 3, "/home/boris/0servfiles/");
strcpy(cmd + 3 + strlen("/home/files/"), line + 2);
strcpy(cmd + 3 + strlen("/home/files/") + strlen(line + 2), " | grep -v xml");
execwthr(cmd, res);
printf("%s\n%s", cmd, res);
free(cmd);
free(res);
} else if (line[0] == 'm') {
if (line[2]=='.' && line[3] == '.') {
printf("forbidden path");
}
unsigned char res = (unsigned char* ) malloc(0xFFFF);
unsigned char* cmd = (unsigned char* ) malloc(strlen(line) +
1 + strlen("/home/files/"));
strcpy(cmd, "mkdir ");
strcpy(cmd + 6, "/home/files/");
strcpy(cmd + 6 + strlen("/home/files/"), line + 2);
execwthr(cmd, res);
printf("%s\n%s", cmd, res);
free(cmd);
free(res);
}
}
return (EXIT_SUCCESS);
}
有一个小问题。当我尝试创建一个名为“h”的文件夹时,我得到以下信息:
m l
mkdir /home/files)l
怎么了?提前致谢!