0

As far as I know The cause of this signal is attempting to find give more data than the specified amount to an array. Right now, I'm trying to write a program that catches the signal, but what i'm doing wrong is I'm catching the Abort signal rather than whatever signal causes "stack smashing" I don't expect to get a paragraph of an answer since I'm just asking for a name, and I don't know where I'm not looking. This is my code if it matters;

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<signal.h>
#include<unistd.h>

void func(char ** argv) {
        char arr[2]; //here's the source of the problem i'm inventing, only two chars allowed
        strcpy(arr, argv[1]);
        return;
}
void handle_fault(int signal) {
        printf("Bad Access\n");
        exit(-1);
}
void handle_abort(int no) {
        printf("Max two chars\n"); //I dont want to see the "*** stack smashing detected ***: terminated" error at all if possible
        exit (-2);
}
int main(int argc, char *argv[]) {
        signal(SIGSEGV, handle_fault);
        signal(SIGABRT, handle_abort);
        func(argv);
        return 0;
}

0 Answers0