~herrhotzenplotz/gcli-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2

[PATCH gcli] Fix uninitialised jsongen structs

Details
Message ID
<20241224000856.25065-1-lhr@disroot.org>
DKIM signature
pass
Download raw message
Patch: +4 -2
- Uninitialised jsongen in gcli-forks causes an infinite loop in fit(), where
  capacity is doubled until a string fits, but capacity is 0 so doubling does
  nothing
- Also change what looks to me like unbalanced gcli_jsongen_{begin,end}_*
  calls in src/github/issues.c
---
 src/github/forks.c  | 1 +
 src/github/issues.c | 4 ++--
 src/gitlab/forks.c  | 1 +
 3 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/github/forks.c b/src/github/forks.c
index 96a9a6f1..c84cc1ca 100644
--- a/src/github/forks.c
+++ b/src/github/forks.c
@@ -76,6 +76,7 @@ github_fork_create(struct gcli_ctx *ctx,
	if (in) {
		struct gcli_jsongen gen = {0};

		gcli_jsongen_init(&gen);
		gcli_jsongen_begin_object(&gen);
		{
			gcli_jsongen_objmember(&gen, "organization");
diff --git a/src/github/issues.c b/src/github/issues.c
index 88cf8bbb..2de9e10e 100644
--- a/src/github/issues.c
+++ b/src/github/issues.c
@@ -416,7 +416,7 @@ github_perform_submit_issue(struct gcli_ctx *const ctx,
			gcli_jsongen_string(&gen, opts->body);
		}
	}
	gcli_jsongen_begin_object(&gen);
	gcli_jsongen_end_object(&gen);

	payload = gcli_jsongen_to_string(&gen);
	gcli_jsongen_free(&gen);
@@ -471,7 +471,7 @@ github_issue_assign(struct gcli_ctx *ctx, struct gcli_path const *const path,
		gcli_jsongen_objmember(&gen, "assignees");
		gcli_jsongen_begin_array(&gen);
		gcli_jsongen_string(&gen, assignee);
		gcli_jsongen_end_object(&gen);
		gcli_jsongen_end_array(&gen);
	}
	gcli_jsongen_end_object(&gen);

diff --git a/src/gitlab/forks.c b/src/gitlab/forks.c
index 22fc7027..0b858309 100644
--- a/src/gitlab/forks.c
+++ b/src/gitlab/forks.c
@@ -75,6 +75,7 @@ gitlab_fork_create(struct gcli_ctx *ctx,
	if (in) {
		struct gcli_jsongen gen = {0};

		gcli_jsongen_init(&gen);
		gcli_jsongen_begin_object(&gen);
		{
			gcli_jsongen_objmember(&gen, "namespace_path");
-- 
2.47.1
Details
Message ID
<3NP1ZGH199TTU.2JG6X40ENKY63@triton.lab.herrhotzenplotz.de>
In-Reply-To
<20241224000856.25065-1-lhr@disroot.org> (view parent)
DKIM signature
pass
Download raw message
> - Uninitialised jsongen in gcli-forks causes an infinite loop in fit(), where
>   capacity is doubled until a string fits, but capacity is 0 so doubling does
>   nothing
> - Also change what looks to me like unbalanced gcli_jsongen_{begin,end}_*
>   calls in src/github/issues.c

Good catch! Thanks for the patch, I have applied it.
I'm gonna update the Changelog later as well.

Nico
Details
Message ID
<3MF7V8CWUKMPG.29Z68SDW3GRUZ@triton.lab.herrhotzenplotz.de>
In-Reply-To
<20241224000856.25065-1-lhr@disroot.org> (view parent)
DKIM signature
pass
Download raw message
> - Uninitialised jsongen in gcli-forks causes an infinite loop in fit(), where
>   capacity is doubled until a string fits, but capacity is 0 so doubling does
>   nothing
> - Also change what looks to me like unbalanced gcli_jsongen_{begin,end}_*
>   calls in src/github/issues.c

Actually, no that I am thinking about this... maybe I should change
the return type of the jsongen* functions to void and simply assert
that whatever we pop off the scope stack is of the correct type.

Another solution is to simply add assertions in various places
(which are removed if compiled in non-debug mode).

I'll work on a patch for likely solution #2.

Nico
Reply to thread Export thread (mbox)