mirror of
https://github.com/openbsd/src.git
synced 2026-04-22 05:05:03 +00:00
Test that __pledge_open can bypass unveil.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# $OpenBSD: Makefile,v 1.1 2026/03/27 05:06:33 dgl Exp $
|
||||
# $OpenBSD: Makefile,v 1.2 2026/03/28 07:23:57 dgl Exp $
|
||||
|
||||
PROG= open
|
||||
LDFLAGS= -static
|
||||
@@ -34,6 +34,10 @@ run-devnull: ${PROG}
|
||||
./${PROG} "stdio" /dev/null
|
||||
REGRESS_TARGETS+= run-devnull
|
||||
|
||||
run-devnull-unveil: ${PROG}
|
||||
./${PROG} "stdio" /dev/null / ""
|
||||
REGRESS_TARGETS+= run-devnull-unveil
|
||||
|
||||
run-empty-promises: ${PROG}
|
||||
if ./${PROG} "" /dev/null; \
|
||||
then false; else [[ $$? == 134 ]]; fi
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: open.c,v 1.1 2026/03/27 05:06:33 dgl Exp $ */
|
||||
/* $OpenBSD: open.c,v 1.2 2026/03/28 07:23:57 dgl Exp $ */
|
||||
/*
|
||||
* Copyright (c) 2026 David Leadbeater <dgl@openbsd.org>
|
||||
*
|
||||
@@ -33,16 +33,24 @@ int _libc___pledge_open(char *path, int flags, ...);
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
int fd, i;
|
||||
char *promise, *path;
|
||||
struct stat sb;
|
||||
|
||||
if (argc != 3)
|
||||
if (argc < 3)
|
||||
errx(1, "argc: %d", argc);
|
||||
|
||||
promise = argv[1];
|
||||
path = argv[2];
|
||||
|
||||
if (((argc - 3) % 2) != 0)
|
||||
errx(1, "unveil(x, y) must be balanced");
|
||||
|
||||
for (i = 3; i < argc; i += 2) {
|
||||
if (unveil(argv[i], argv[i+1]) == -1)
|
||||
err(1, "unveil(%s, %s)", argv[i], argv[i+1]);
|
||||
}
|
||||
|
||||
if (strcmp(promise, NO_PLEDGE) != 0 && pledge(promise, NULL) == -1)
|
||||
err(1, "pledge %s", promise);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user