Created
November 12, 2015 05:03
-
-
Save staybuzz/9068559db706e89c7bb7 to your computer and use it in GitHub Desktop.
シグナルハンドラとexecveを使ってみる
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <signal.h> | |
#include <unistd.h> | |
static int *p = NULL; | |
static void execute_command(){ | |
char *argv[] = {"/bin/sh", "-c", "'date'", NULL}; | |
execve(argv[0], argv, NULL); | |
} | |
static void print_message(int x){ /* シグナルハンドラ */ | |
printf("Baz\n"); | |
execute_command(); | |
exit(1); | |
} | |
int main(void){ | |
struct sigaction sa; | |
sa.sa_handler = print_message; | |
sigemptyset(&sa.sa_mask); /* おなじない */ | |
sa.sa_flags = 0; /* おまじない */ | |
sigaction(SIGSEGV, &sa, NULL); /* シグナルハンドラの登録 */ | |
printf("Foo\n"); | |
*p = 99; | |
printf("Bar\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment