Skip to content

Commit

Permalink
Defer heap variable initialisation after pledge
Browse files Browse the repository at this point in the history
Otherwise `AGRS` and `program_arguments` remain allocated/unfreed in the
early (extremely unlikely) pledge(2) failure case.

Move their allocation before jq_init(), the first case of jumping to
`out` where they are cleaned up, where it also seems to logically fit
better than above between function entry, locale setup and OpenBSD
specific pledge.
  • Loading branch information
klemensn authored and nicowilliams committed Oct 22, 2023
1 parent 77dcaf3 commit 7ab117a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,6 @@ int main(int argc, char* argv[]) {
int last_result = -1; /* -1 = no result, 0=null or false, 1=true */
int badwrite;
int options = 0;
jv ARGS = jv_array(); /* positional arguments */
jv program_arguments = jv_object(); /* named arguments */

#ifdef HAVE_SETLOCALE
(void) setlocale(LC_ALL, "");
Expand All @@ -339,6 +337,9 @@ int main(int argc, char* argv[]) {
_setmode(fileno(stderr), _O_TEXT | _O_U8TEXT);
#endif

jv ARGS = jv_array(); /* positional arguments */
jv program_arguments = jv_object(); /* named arguments */

if (argc) progname = argv[0];

jq = jq_init();
Expand Down

0 comments on commit 7ab117a

Please sign in to comment.