Skip to content

Commit

Permalink
Add option to use mmap2
Browse files Browse the repository at this point in the history
  • Loading branch information
csersoft committed Apr 30, 2021
1 parent 48b29c3 commit 522698d
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/shc.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static const char * abstract[] = {
0};

static const char usage[] =
"Usage: shc [-e date] [-m addr] [-i iopt] [-x cmd] [-l lopt] [-o outfile] [-rvDSUHCABh] -f script";
"Usage: shc [-e date] [-m addr] [-i iopt] [-x cmd] [-l lopt] [-o outfile] [-rvDSUHCAB2h] -f script";

static const char * help[] = {
"",
Expand All @@ -89,6 +89,7 @@ static const char * help[] = {
" -C Display license and exit",
" -A Display abstract and exit",
" -B Compile for busybox",
" -2 Use the system call mmap2",
" -h Display help and exit",
"",
" Environment variables used:",
Expand Down Expand Up @@ -142,6 +143,9 @@ static int TRACEABLE_flag = 1;
static const char HARDENING_line[] =
"#define HARDENING %d /* Define as 1 to disable ptrace/dump the executable */\n";
static int HARDENING_flag = 0;
static const char MMAP2_line[] =
"#define MMAP2 %d /* Define as 1 to use syscall mmap2 */\n";
static int MMAP2_flag = 0;
static const char BUSYBOXON_line[] =
"#define BUSYBOXON %d /* Define as 1 to enable work with busybox */\n";
static int BUSYBOXON_flag = 0;
Expand Down Expand Up @@ -338,7 +342,11 @@ static const char * RTC[] = {
" /* list of allowed syscalls */",
" Allow(exit_group), /* exits a process */",
" Allow(brk), /* for malloc(), inside libc */",
"#if MMAP2",
" Allow(mmap2), /* also for malloc() */",
"#else",
" Allow(mmap), /* also for malloc() */",
"#endif",
" Allow(munmap), /* for free(), inside libc */",
"",
" /* and if we don't match above, die */",
Expand Down Expand Up @@ -751,7 +759,7 @@ static const char * RTC[] = {
static int parse_an_arg(int argc, char * argv[])
{
extern char * optarg;
const char * opts = "e:m:f:i:x:l:o:rvDSUHCABh";
const char * opts = "e:m:f:i:x:l:o:rvDSUHCAB2h";
struct tm tmp[1];
time_t expdate;
int cnt, l;
Expand Down Expand Up @@ -853,6 +861,9 @@ static int parse_an_arg(int argc, char * argv[])
case 'B':
BUSYBOXON_flag = 1;
break;
case '2':
MMAP2_flag = 1;
break;
case ':':
fprintf(stderr, "%s parse: Missing parameter\n", my_name);
return -1;
Expand Down Expand Up @@ -1277,6 +1288,7 @@ int write_C(char * file, char * argv[])
fprintf(o, TRACEABLE_line, TRACEABLE_flag);
fprintf(o, HARDENING_line, HARDENING_flag);
fprintf(o, BUSYBOXON_line, BUSYBOXON_flag);
fprintf(o, MMAP2_line, MMAP2_flag);
for (indx = 0; RTC[indx]; indx++)
fprintf(o, "%s\n", RTC[indx]);
fflush(o);
Expand Down

0 comments on commit 522698d

Please sign in to comment.