I'm writing a simple program in 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);
}
There's one small problem. When I try to create a folder named "h" I get following:
m l
mkdir /home/files)l
What's wrong? thanks in advance!