Why is this chuck of code giving me a segmentation fault and how do I fix it?
int found = 0;
                Rule *dep_rule = head;
                while(dep_rule != NULL){
                    if(strcmp(dep_rule->target, dep_name)==0){
                        dep->rule = dep_rule;
                        found = 1;
                        break;
                    }
                    dep_rule = dep_rule->next_rule;
                }
                if(found == 0){
                    dep_rule = malloc(sizeof(Rule));
                    if(dep_rule == NULL){
                        perror("malloc");
                        exit(1);
                    }
                    dep_rule->target = malloc(sizeof(char) * strlen(dep_name));
                    if(dep_rule->target == NULL){
                        perror("malloc");
                        exit(1);
                    }
                    strncpy(dep_rule->target, dep_name, strlen(dep_name));
                    dep_rule->dependencies = NULL;
                    dep_rule->actions = NULL;
                    dep_rule->next_rule = NULL;
                }