From 51f0b0211bf8bb919ce5d3e600b7a7e281baba1f Mon Sep 17 00:00:00 2001 From: Peter Pettersson Date: Fri, 17 Nov 2023 18:25:09 +0100 Subject: [PATCH 1/5] util: make git_futils_readbuffer_updated header match source --- src/util/futils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/futils.h b/src/util/futils.h index 3f207afb2f2..53bcc551890 100644 --- a/src/util/futils.h +++ b/src/util/futils.h @@ -25,7 +25,7 @@ extern int git_futils_readbuffer(git_str *obj, const char *path); extern int git_futils_readbuffer_updated( git_str *obj, const char *path, - unsigned char checksum[GIT_HASH_SHA1_SIZE], + unsigned char checksum[GIT_HASH_SHA256_SIZE], int *updated); extern int git_futils_readbuffer_fd_full(git_str *obj, git_file fd); extern int git_futils_readbuffer_fd(git_str *obj, git_file fd, size_t len); From 1f54d5bb5aae79b4f0ebd7767bac671903e54ed5 Mon Sep 17 00:00:00 2001 From: Peter Pettersson Date: Fri, 17 Nov 2023 19:19:12 +0100 Subject: [PATCH 2/5] util: suppress some uninitialized variable warnings --- src/util/net.c | 2 +- src/util/regexp.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/net.c b/src/util/net.c index afd52ce0830..24782d2af09 100644 --- a/src/util/net.c +++ b/src/util/net.c @@ -657,7 +657,7 @@ static bool has_at(const char *str) int git_net_url_parse_scp(git_net_url *url, const char *given) { const char *default_port = default_port_for_scheme("ssh"); - const char *c, *user, *host, *port, *path = NULL; + const char *c, *user, *host, *port = NULL, *path = NULL; size_t user_len = 0, host_len = 0, port_len = 0; unsigned short bracket = 0; diff --git a/src/util/regexp.c b/src/util/regexp.c index 08700882bc3..eb45822474d 100644 --- a/src/util/regexp.c +++ b/src/util/regexp.c @@ -125,7 +125,7 @@ int git_regexp_search(const git_regexp *r, const char *string, size_t nmatches, if ((data = pcre2_match_data_create(nmatches, NULL)) == NULL) { git_error_set_oom(); - goto out; + return -1; } if ((error = pcre2_match(*r, (const unsigned char *) string, strlen(string), From db013b5333e8f0808ea7cdf91ab7398b1e835181 Mon Sep 17 00:00:00 2001 From: Peter Pettersson Date: Mon, 20 Nov 2023 10:18:22 +0100 Subject: [PATCH 3/5] util: replace index (deprecated) with strchr --- src/util/unix/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/unix/process.c b/src/util/unix/process.c index 7f88ccff067..0c2029acb95 100644 --- a/src/util/unix/process.c +++ b/src/util/unix/process.c @@ -37,7 +37,7 @@ struct git_process { GIT_INLINE(bool) is_delete_env(const char *env) { - char *c = index(env, '='); + char *c = strchr(env, '='); if (c == NULL) return false; From 3889ea5eb173b2bd9366e9547da62b3b932c5683 Mon Sep 17 00:00:00 2001 From: Peter Pettersson Date: Mon, 20 Nov 2023 10:42:12 +0100 Subject: [PATCH 4/5] util: include git2/deprecated.h in errors.c In C99 functions need to be declared before they are defined. We could just add the declarations before them, but including the header allows the compiler to warn if they differ. --- src/util/errors.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/util/errors.c b/src/util/errors.c index 68e7a415625..feed6a835f5 100644 --- a/src/util/errors.c +++ b/src/util/errors.c @@ -376,6 +376,9 @@ void git_error_system_set(int code) /* Deprecated error values and functions */ #ifndef GIT_DEPRECATE_HARD + +#include "git2/deprecated.h" + const git_error *giterr_last(void) { return git_error_last(); From bde119e71a3364d3abd8201fc91da15baff99224 Mon Sep 17 00:00:00 2001 From: Peter Pettersson Date: Sun, 26 Nov 2023 01:02:47 +0100 Subject: [PATCH 5/5] util: sudo_uid_lookup should always return error if out isn't set --- src/util/fs_path.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/util/fs_path.c b/src/util/fs_path.c index e03fcf7c760..ab64778c23e 100644 --- a/src/util/fs_path.c +++ b/src/util/fs_path.c @@ -1938,12 +1938,13 @@ static int sudo_uid_lookup(uid_t *out) { git_str uid_str = GIT_STR_INIT; int64_t uid; - int error; + int error = -1; - if ((error = git__getenv(&uid_str, "SUDO_UID")) == 0 && - (error = git__strntol64(&uid, uid_str.ptr, uid_str.size, NULL, 10)) == 0 && - uid == (int64_t)((uid_t)uid)) { + if (git__getenv(&uid_str, "SUDO_UID") == 0 && + git__strntol64(&uid, uid_str.ptr, uid_str.size, NULL, 10) == 0 && + uid == (int64_t)((uid_t)uid)) { *out = (uid_t)uid; + error = 0; } git_str_dispose(&uid_str);