Skip to content

Commit

Permalink
remove quotes around command if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyYakubov committed Jan 6, 2024
1 parent 48e633e commit 984eba5
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion server_side/c/run_as_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ char *copy_until_separator(const char *src, const char *separator) {
return dest;
}

char* remove_quotes(const char *str) {
int len = strlen(str);
char *result;
if (len >= 2 && str[0] == '\'' && str[len - 1] == '\'') {
result = (char *)malloc(len - 1);
strncpy(result, str + 1, len - 2);
result[len - 2] = '\0';
return result;
} else {
result = (char *)malloc(len+1);
strcpy(result, str);
}
return result;
}

void sha256_string(const char *string, char outputBuffer[65]) {
unsigned char hash[SHA256_DIGEST_LENGTH];
SHA256_CTX sha256;
Expand Down Expand Up @@ -123,7 +138,9 @@ int main(int argc, char *argv[]) {
exit(1);
}
if (strcmp(argv[3], "-c") == 0) {
int res = system(argv[4]);
char* command = remove_quotes(argv[4]);
int res = system(command);
free(command);
exit(res == 0 ? 0 : 1);
} else if (strcmp(argv[3], "-f") == 0) {
int fd = open(argv[4], O_RDONLY);
Expand Down

0 comments on commit 984eba5

Please sign in to comment.