Skip to content

Commit

Permalink
Coverage: add a flag to disable capsicum when running for coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
bapt committed Dec 10, 2021
1 parent 7347761 commit e9c06cd
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libpkg/triggers.c
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,11 @@ trigger_execute_lua(const char *script, bool sandbox, pkghash *args)
lua_args_table(L, arguments, i);
#ifdef HAVE_CAPSICUM
if (sandbox) {
#ifndef defined(PKG_COVERAGE)
if (cap_enter() < 0 && errno != ENOSYS) {
err(1, "cap_enter failed");
}
#endif
}
#endif
if (luaL_dostring(L, script)) {
Expand Down
2 changes: 2 additions & 0 deletions src/audit.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,14 @@ exec_audit(int argc, char **argv)

/* Now we have vulnxml loaded and check list formed */
#ifdef HAVE_CAPSICUM
#ifndef PKG_COVERAGE
if (cap_enter() < 0 && errno != ENOSYS) {
warn("cap_enter() failed");
pkg_audit_free(audit);
pkghash_destroy(check);
return (EPKG_FATAL);
}
#endif
#endif

if (pkg_audit_process(audit) == EPKG_OK) {
Expand Down
2 changes: 2 additions & 0 deletions src/clean.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,13 @@ exec_clean(int argc, char **argv)
return (EXIT_FAILURE);
}

#ifndef PKG_COVERAGE
if (cap_enter() < 0 && errno != ENOSYS) {
warn("cap_enter() failed");
close(cachefd);
return (EXIT_FAILURE);
}
#endif
#endif

kv_init(dl);
Expand Down
4 changes: 4 additions & 0 deletions src/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,12 @@ event_sandboxed_call(pkg_sandbox_cb func, int fd, void *ud)

/* Here comes child process */
#ifdef HAVE_CAPSICUM
#ifndef PKG_COVERAGE
if (cap_enter() < 0 && errno != ENOSYS) {
warn("cap_enter() failed");
_exit(EXIT_FAILURE);
}
#endif
#endif

ret = func(fd, ud);
Expand Down Expand Up @@ -332,10 +334,12 @@ event_sandboxed_get_string(pkg_sandbox_cb func, char **result, int64_t *len,
err(EXIT_FAILURE, "Unable to setrlimit(RLIMIT_NPROC)");

#ifdef HAVE_CAPSICUM
#ifndef PKG_COVERAGE
if (cap_enter() < 0 && errno != ENOSYS) {
warn("cap_enter() failed");
return (EPKG_FATAL);
}
#endif
#endif

ret = func(pair[0], ud);
Expand Down
2 changes: 2 additions & 0 deletions src/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,13 @@ exec_info(int argc, char **argv)
return (EXIT_FAILURE);
}

#ifndef PKG_COVERAGE
if (cap_enter() < 0 && errno != ENOSYS) {
warn("cap_enter() failed");
close(fd);
return (EXIT_FAILURE);
}
#endif
#endif
if (opt == INFO_TAG_NAMEVER)
opt |= INFO_FULL;
Expand Down
2 changes: 2 additions & 0 deletions src/ssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ exec_ssh(int argc, char **argv __unused)
return (EXIT_FAILURE);
}

#ifndef PKG_COVERAGE
if (cap_enter() < 0 && errno != ENOSYS) {
warn("cap_enter() failed");
close(fd);
return (EXIT_FAILURE);
}
#endif

#endif
if (pkg_sshserve(fd) != EPKG_OK) {
Expand Down
2 changes: 2 additions & 0 deletions src/updating.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,13 @@ exec_updating(int argc, char **argv)
return (EXIT_FAILURE);
}

#ifndef PKG_COVERAGE
if (cap_enter() < 0 && errno != ENOSYS) {
warn("cap_enter() failed");
fclose(fd);
return (EXIT_FAILURE);
}
#endif
#endif

SLIST_INIT(&origins);
Expand Down
2 changes: 2 additions & 0 deletions src/upgrade.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,15 @@ check_vulnerable(struct pkg_audit *audit, struct pkgdb *db, int sock)
drop_privileges();

#ifdef HAVE_CAPSICUM
#ifndef PKG_COVERAGE
if (cap_enter() < 0 && errno != ENOSYS) {
warn("cap_enter() failed");
pkg_audit_free(audit);
pkghash_destroy(check);
fclose(out);
return;
}
#endif
#endif

if (pkg_audit_process(audit) == EPKG_OK) {
Expand Down

0 comments on commit e9c06cd

Please sign in to comment.