From c51851396d81e08011bc4d37f7f096e753cc05cb Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Sat, 26 Jun 2021 14:13:08 -0400 Subject: Added some more error checking in `create_info()`. --- git.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/git.c b/git.c index 9632d21..3c84378 100644 --- a/git.c +++ b/git.c @@ -69,11 +69,27 @@ pull_request *get_pull_request(int id, const char *root) { } int create_info(pull_request *pr, const char *pr_dir) { - int len = strlen(pr_dir) + strlen("/info"); - char *info = calloc(len+1, sizeof(char)); + int len; + int buf_len; + char *info; char *info_buf; FILE *fp; + /* Is the PR NULL? */ + if (pr == NULL) { + log(LOG_ERR,"Pull request is NULL."); + return 0; + } + /* Is the PR directory NULL? */ + if (pr_dir == NULL) { + log(LOG_ERR,"Pull request directory is NULL."); + return 0; + } + + len = strlen(pr_dir) + strlen("/info"); + buf_len = get_info_len(pr); + info = calloc(len+1, sizeof(char)); + /* Append /info to the PR directory. */ sprintf(info, "%s/info", pr_dir); -- cgit v1.2.3-13-gbd6f