Whenever a pull request is submitted on Gitea and it has the project
owners set as reviewers (not one by one but just a generic everyone)
the reviewers array contains a single NULL which is being dereferenced
later.
Fix by replacing NULLs in the retrieved array by a malloced string
stating the project owners as reviewers.
Fixes: https://gitlab.com/herrhotzenplotz/gcli/issues/222
Signed-off-by: Nico Sonack <nsonack@herrhotzenplotz.de>
---
src/gitea/pulls.c | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/src/gitea/pulls.c b/src/gitea/pulls.c
index 7489c58..707ba8b 100644
--- a/src/gitea/pulls.c
+++ b/src/gitea/pulls.c
@@ -100,7 +100,21 @@ int
gitea_get_pull(struct gcli_ctx *ctx, char const *owner, char const *repo,
gcli_id const pr_number, struct gcli_pull *const out)
{
- return github_get_pull(ctx, owner, repo, pr_number, out);
+ int const rc = github_get_pull(ctx, owner, repo, pr_number, out);
+
+ if (rc == 0) {
+ /* fix for https://gitlab.com/herrhotzenplotz/gcli/issues/222:
+ *
+ * Sometimes the "reviewers" array contains a single NULL value
+ * that means that this pull request is to be reviewed by the
+ * owners of the repository. */
+ for (size_t i = 0; i < out->reviewers_size; ++i) {
+ if (out->reviewers[i] == NULL)
+ out->reviewers[i] = sn_asprintf("%s/Owners", owner);
+ }
+ }
+
+ return rc;
}
int
--
2.44.0