Skip to content

Commit

Permalink
Fix potential segfault
Browse files Browse the repository at this point in the history
  • Loading branch information
solkin committed Mar 22, 2020
1 parent c436157 commit b2a9432
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions siphon.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ int open_file(const char *file_path, int flags);

int open_socket(const char *ip);

int send_files(unsigned char **files_path, int files_count, int sock);
int send_files(char **files_path, int files_count, int sock);

int load_file(const char *directory, int sock);

Expand Down Expand Up @@ -79,7 +79,7 @@ static struct winsize tty_size;
* Main method
*/
int main(int argc, char **argv) {
unsigned char **files = (unsigned char **) malloc(sizeof(unsigned char *));
char **files = malloc(0);
int c, files_count = 0;
char *host = NULL;
while (1) {
Expand Down Expand Up @@ -123,10 +123,17 @@ int main(int argc, char **argv) {
case 'p':
port = *(int *) optarg;
break;
case 'f':
files[files_count] = (unsigned char *) optarg;
case 'f': {
char **updated = malloc((files_count + 1) * sizeof(char *));
for (int i = 0; i < files_count; i++) {
updated[i] = files[i];
}
free(files);
files = updated;
files[files_count] = optarg;
files_count += 1;
break;
}
case 'b':
buffer_size = *(int *) optarg;
break;
Expand Down Expand Up @@ -224,7 +231,7 @@ int open_socket(const char *ip) {
}
}

int send_files(unsigned char **files_path, int files_count, int sock) {
int send_files(char **files_path, int files_count, int sock) {
char block_type;
int file, c;
int trans_cond = EXIT_SUCCESS;
Expand Down

0 comments on commit b2a9432

Please sign in to comment.