Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restrict systems operations on OpenBSD #2934

Merged
merged 3 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ if test "x$valgrind_cmd" = "x" ; then
AC_MSG_WARN([valgrind is required to test jq.])
fi
AC_CHECK_FUNCS(memmem)
AC_CHECK_FUNCS(mkstemp)

AC_CHECK_HEADER("sys/cygwin.h", [have_cygwin=1;])
AC_CHECK_HEADER("shlwapi.h",[have_shlwapi=1;])
Expand Down
7 changes: 7 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,13 @@ int main(int argc, char* argv[]) {
(void) setlocale(LC_ALL, "");
#endif

#ifdef __OpenBSD__
if (pledge("stdio rpath", NULL) == -1) {
perror("pledge");
exit(JQ_ERROR_SYSTEM);
klemensn marked this conversation as resolved.
Show resolved Hide resolved
}
#endif

#ifdef WIN32
jv_tsd_dtoa_ctx_init();
fflush(stdout);
Expand Down
21 changes: 0 additions & 21 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,27 +79,6 @@ FILE *fopen(const char *fname, const char *mode) {
}
#endif

#ifndef HAVE_MKSTEMP
int mkstemp(char *template) {
size_t len = strlen(template);
int tries=5;
int fd;

// mktemp() truncates template when it fails
char *s = alloca(len + 1);
assert(s != NULL);
strcpy(s, template);

do {
// Restore template
strcpy(template, s);
(void) mktemp(template);
fd = open(template, O_CREAT | O_EXCL | O_RDWR, 0600);
} while (fd == -1 && tries-- > 0);
return fd;
}
#endif

jv expand_path(jv path) {
assert(jv_get_kind(path) == JV_KIND_STRING);
const char *pstr = jv_string_value(path);
Expand Down
4 changes: 0 additions & 4 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@

#include "jv.h"

#ifndef HAVE_MKSTEMP
int mkstemp(char *template);
#endif

jv expand_path(jv);
jv get_home(void);
jv jq_realpath(jv);
Expand Down