running this results in stack smashing error, how to fix?
#include <stdio.h>
#include <stdlib.h>


// TODO: Implement a helper named check_permissions that matches the prototype below.
int check_permissions(char *given, char *required){
    for (int i = 0; i < 9; i++) {
        if (required[i] != '-' && given[i] == '-') {
            return 1;
        }
    }
    return 0;
}


int main(int argc, char** argv) {
    if (!(argc == 2 || argc == 3)) {
        fprintf(stderr, "USAGE: count_large size [permissions]\n");
        return 1;
    }

    int req_size = strtol(argv[1], NULL, 10);

    char *permissions = malloc(10 * sizeof(char));
    int file_size;

    int counter = 0;

    scanf("%*[^\n]");

    while (scanf("%s %*i %*s %*s %i %*s %*i %*s %*s", permissions, &file_size) != EOF) {

        if (permissions[0] != 'd') {
            if (argc == 3 && file_size >= req_size) {
                    char *required = argv[2];
                    if (check_permissions(permissions, required) == 0) {
                        counter += 1;
                    }
            }
            else if (file_size >= req_size) {
                        counter += 1;
                    }
            }
        }

        printf("%i \n", counter);


    // TODO: Process command line arguments.

    // TODO: Call check_permissions as part of your solution to count the files to
    // compute and print the correct value.

    free(permissions);

    return 0;
}
