]> git.ipfire.org Git - pakfire.git/commitdiff
tests: command: Add a command that immediately causes SEGV
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 13 Dec 2022 11:02:02 +0000 (11:02 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 13 Dec 2022 11:02:02 +0000 (11:02 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
tests/stub/command.c

index 9549ebc0a28c756bb272de624a1ca6c34b27321b..42d005cb34c4511419fc5e1f696bb22beaddfd84 100644 (file)
@@ -363,6 +363,18 @@ static int _pipe(int argc, char* argv[]) {
        return 0;
 }
 
+/*
+       Causes a segmentation fault so this program is being terminated
+*/
+static int _segv(int argc, char* argv[]) {
+       char* p = NULL;
+
+       // Storing a value to the NULL pointer
+       *p = 'a';
+
+       return 0;
+}
+
 int main(int argc, char* argv[]) {
        if (argc < 2) {
                fprintf(stderr, "No command given\n");
@@ -414,6 +426,10 @@ int main(int argc, char* argv[]) {
        else if (strcmp(command, "print-pid") == 0)
                callback = print_pid;
 
+       // SEGV
+       else if (strcmp(command, "segv") == 0)
+               callback = _segv;
+
        // Send signal
        else if (strcmp(command, "send-signal") == 0)
                callback = send_signal;