{"thread":{"id":"60044","subject":"[PATCH 0/3] sha256/gcrypt fixes","startedAt":"2023-07-31T12:15:29Z","lastAt":"2023-07-31T15:58:48Z","messageCount":5,"participants":["Eric Wong","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"479990","messageId":"20230731120808.1230210-1-e@80x24.org","threadId":"60044","inReplyTo":null,"subject":"[PATCH 0/3] sha256/gcrypt fixes","fromName":"Eric Wong","fromEmail":"e@80x24.org","sentAt":"2023-07-31T12:08:05Z","receivedAt":"2023-07-31T12:15:29Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"I noticed problems requiring patches 2 and 3 while eyeballing\nthe code, but had to come up with the first one to fix\nSANITIZE=leak, first.\n\nEric Wong (3):\n  sha256/gcrypt: fix build with SANITIZE=leak\n  sha256/gcrypt: fix memory leak with SHA-256 repos\n  sha256/gcrypt: die on gcry_md_open failures\n\n sha256/gcrypt.h | 13 ++++++++-----\n 1 file changed, 8 insertions(+), 5 deletions(-)\n"},{"id":"479991","messageId":"20230731120808.1230210-2-e@80x24.org","threadId":"60044","inReplyTo":"20230731120808.1230210-1-e@80x24.org","subject":"[PATCH 1/3] sha256/gcrypt: fix build with SANITIZE=leak","fromName":"Eric Wong","fromEmail":"e@80x24.org","sentAt":"2023-07-31T12:08:06Z","receivedAt":"2023-07-31T12:15:42Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"Non-static functions cause `undefined reference' errors when\nbuilding with `SANITIZE=leak' due to the lack of prototypes.\nMark all these functions as `static inline' as we do in\nsha256/nettle.h to avoid the need to maintain prototypes.\n\nSigned-off-by: Eric Wong <e@80x24.org>\n---\n sha256/gcrypt.h | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/sha256/gcrypt.h b/sha256/gcrypt.h\nindex 501da5ed91..68cf6b6a54 100644\n--- a/sha256/gcrypt.h\n+++ b/sha256/gcrypt.h\n@@ -7,22 +7,22 @@\n \n typedef gcry_md_hd_t gcrypt_SHA256_CTX;\n \n-inline void gcrypt_SHA256_Init(gcrypt_SHA256_CTX *ctx)\n+static inline void gcrypt_SHA256_Init(gcrypt_SHA256_CTX *ctx)\n {\n \tgcry_md_open(ctx, GCRY_MD_SHA256, 0);\n }\n \n-inline void gcrypt_SHA256_Update(gcrypt_SHA256_CTX *ctx, const void *data, size_t len)\n+static inline void gcrypt_SHA256_Update(gcrypt_SHA256_CTX *ctx, const void *data, size_t len)\n {\n \tgcry_md_write(*ctx, data, len);\n }\n \n-inline void gcrypt_SHA256_Final(unsigned char *digest, gcrypt_SHA256_CTX *ctx)\n+static inline void gcrypt_SHA256_Final(unsigned char *digest, gcrypt_SHA256_CTX *ctx)\n {\n \tmemcpy(digest, gcry_md_read(*ctx, GCRY_MD_SHA256), SHA256_DIGEST_SIZE);\n }\n \n-inline void gcrypt_SHA256_Clone(gcrypt_SHA256_CTX *dst, const gcrypt_SHA256_CTX *src)\n+static inline void gcrypt_SHA256_Clone(gcrypt_SHA256_CTX *dst, const gcrypt_SHA256_CTX *src)\n {\n \tgcry_md_copy(dst, *src);\n }\n"},{"id":"479992","messageId":"20230731120808.1230210-3-e@80x24.org","threadId":"60044","inReplyTo":"20230731120808.1230210-1-e@80x24.org","subject":"[PATCH 2/3] sha256/gcrypt: fix memory leak with SHA-256 repos","fromName":"Eric Wong","fromEmail":"e@80x24.org","sentAt":"2023-07-31T12:08:07Z","receivedAt":"2023-07-31T12:15:48Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"`gcry_md_open' needs to be paired with `gcry_md_close' to ensure\nresources are released.  Since our internal APIs don't have\nseparate close/release callbacks, sticking it into the finalization\ncallback seems appropriate.\n\nBuilding with SANITIZE=leak and running `git fsck' on a SHA-256\nrepository no longer reports leaks.\n\nSigned-off-by: Eric Wong <e@80x24.org>\n---\n sha256/gcrypt.h | 1 +\n 1 file changed, 1 insertion(+)\n\ndiff --git a/sha256/gcrypt.h b/sha256/gcrypt.h\nindex 68cf6b6a54..1d06a778af 100644\n--- a/sha256/gcrypt.h\n+++ b/sha256/gcrypt.h\n@@ -20,6 +20,7 @@ static inline void gcrypt_SHA256_Update(gcrypt_SHA256_CTX *ctx, const void *data\n static inline void gcrypt_SHA256_Final(unsigned char *digest, gcrypt_SHA256_CTX *ctx)\n {\n \tmemcpy(digest, gcry_md_read(*ctx, GCRY_MD_SHA256), SHA256_DIGEST_SIZE);\n+\tgcry_md_close(*ctx);\n }\n \n static inline void gcrypt_SHA256_Clone(gcrypt_SHA256_CTX *dst, const gcrypt_SHA256_CTX *src)\n"},{"id":"479993","messageId":"20230731120808.1230210-4-e@80x24.org","threadId":"60044","inReplyTo":"20230731120808.1230210-1-e@80x24.org","subject":"[PATCH 3/3] sha256/gcrypt: die on gcry_md_open failures","fromName":"Eric Wong","fromEmail":"e@80x24.org","sentAt":"2023-07-31T12:08:08Z","receivedAt":"2023-07-31T12:15:52Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"`gcry_md_open' allocates memory and must (like all allocation\nfunctions) be checked for failure.\n\nSigned-off-by: Eric Wong <e@80x24.org>\n---\n sha256/gcrypt.h | 4 +++-\n 1 file changed, 3 insertions(+), 1 deletion(-)\n\ndiff --git a/sha256/gcrypt.h b/sha256/gcrypt.h\nindex 1d06a778af..17a90f1052 100644\n--- a/sha256/gcrypt.h\n+++ b/sha256/gcrypt.h\n@@ -9,7 +9,9 @@ typedef gcry_md_hd_t gcrypt_SHA256_CTX;\n \n static inline void gcrypt_SHA256_Init(gcrypt_SHA256_CTX *ctx)\n {\n-\tgcry_md_open(ctx, GCRY_MD_SHA256, 0);\n+\tgcry_error_t err = gcry_md_open(ctx, GCRY_MD_SHA256, 0);\n+\tif (err)\n+\t\tdie(\"gcry_md_open: %s\", gcry_strerror(err));\n }\n \n static inline void gcrypt_SHA256_Update(gcrypt_SHA256_CTX *ctx, const void *data, size_t len)\n"},{"id":"480000","messageId":"xmqqy1iwyswr.fsf@gitster.g","threadId":"60044","inReplyTo":"20230731120808.1230210-1-e@80x24.org","subject":"Re: [PATCH 0/3] sha256/gcrypt fixes","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-07-31T15:58:28Z","receivedAt":"2023-07-31T15:58:48Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Eric Wong <e@80x24.org> writes:\n\n> I noticed problems requiring patches 2 and 3 while eyeballing\n> the code, but had to come up with the first one to fix\n> SANITIZE=leak, first.\n\nThanks.\n\n>\n> Eric Wong (3):\n>   sha256/gcrypt: fix build with SANITIZE=leak\n>   sha256/gcrypt: fix memory leak with SHA-256 repos\n>   sha256/gcrypt: die on gcry_md_open failures\n>\n>  sha256/gcrypt.h | 13 ++++++++-----\n>  1 file changed, 8 insertions(+), 5 deletions(-)\n"}]}