Skip to content

Commit 4f03f1b

Browse files
committed
Add unveil(2) support (OpenBSD only).
1 parent feb499d commit 4f03f1b

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

configure

+24
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,21 @@ EOF
185185
fi
186186
}
187187

188+
unveilcheck() {
189+
cat << EOF > conftest.c
190+
#include <unistd.h>
191+
int main(void){unveil(NULL,NULL);return 0;}
192+
EOF
193+
$cc $cflags $ldflags -o conftest conftest.c > /dev/null 2>&1
194+
if [ $? -eq 0 ] ; then
195+
rm -f conftest conftest.o conftest.c
196+
return 0
197+
else
198+
rm -f conftest conftest.o conftest.c
199+
return 1
200+
fi
201+
}
202+
188203
prefix="/usr/local"
189204
libs=""
190205
libbsd=0
@@ -293,6 +308,15 @@ else
293308
echo "no"
294309
fi
295310

311+
printf "checking for unveil... "
312+
unveilcheck
313+
if [ $? -eq 0 ] ; then
314+
cflags="$cflags -DHAVE_UNVEIL"
315+
echo "yes"
316+
else
317+
echo "no"
318+
fi
319+
296320
if [ $libbsd -eq 1 ] ; then
297321
printf "checking for libbsd... "
298322
libbsdcheck

shuf.c

+15-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ static void __dead
184184
version(void)
185185
{
186186

187-
fputs("shuf 2.5\n"
187+
fputs("shuf 2.6\n"
188188
"Copyright (c) 2017-2019 Brian Callahan <[email protected]>\n"
189189
"\nPermission to use, copy, modify, and distribute this software"
190190
" for any\npurpose with or without fee is hereby granted, "
@@ -213,7 +213,11 @@ main(int argc, char *argv[])
213213
size_t buflen = 0, bufsize = 8192, nbufsize;
214214

215215
#ifdef HAVE_PLEDGE
216+
#ifdef HAVE_UNVEIL
217+
if (pledge("stdio rpath wpath cpath unveil", NULL) == -1)
218+
#else
216219
if (pledge("stdio rpath wpath cpath", NULL) == -1)
220+
#endif
217221
errx(1, "pledge");
218222
#endif
219223

@@ -261,9 +265,19 @@ main(int argc, char *argv[])
261265
if (oflag++)
262266
errx(1, "cannot have multiple -o");
263267

268+
#ifdef HAVE_UNVEIL
269+
if (unveil(optarg, "wc") == -1)
270+
err(1, "unveil");
271+
#endif
272+
264273
if ((ofile = fopen(optarg, "w")) == NULL)
265274
err(1, "couldn't open output file %s", optarg);
266275

276+
#ifdef HAVE_UNVEIL
277+
if (unveil(NULL, NULL) == -1)
278+
err(1, "unveil");
279+
#endif
280+
267281
break;
268282
case 'r':
269283
rflag = 1;

0 commit comments

Comments
 (0)