From 5cdb857988eeb627a66d5f9deca73b1b47931172 Mon Sep 17 00:00:00 2001 From: ngn Date: Thu, 11 Jul 2024 07:52:00 +0300 Subject: [PATCH] fix: correct reading for hash function --- Makefile | 2 +- README.md | 1 + examples/client/check.c | 12 ++++++++++++ locale/tr/LC_MESSAGES/libmp.po | 2 +- src/ctx/check.c | 2 ++ src/database/files.c | 8 +++++--- src/util.c | 6 ++++-- 7 files changed, 26 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index ae1f532..4be1007 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ SRCS = $(wildcard src/*.c) $(wildcard src/*/*.c) OBJS = $(patsubst src/%.c,dist/%.o,$(SRCS)) HDRS = $(wildcard include/*.h) CFLAGS = -O3 -fstack-protector-strong -fcf-protection=full -fstack-clash-protection -LIBS = -lpthread -larchive -linih -lgpgme -lsqlite3 +LIBS = -lpthread -lcrypto -larchive -linih -lgpgme -lsqlite3 DEBUG = 0 VERSION = 24.00 diff --git a/README.md b/README.md index 86ae1a8..99e6d0e 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ it from the source and install it. To this you will need the following tools and libraries: - gcc - make +- openssl - libarchive - libinih - gettext diff --git a/examples/client/check.c b/examples/client/check.c index 8b2ba1e..9e866e7 100644 --- a/examples/client/check.c +++ b/examples/client/check.c @@ -17,6 +17,11 @@ int main(int argc, char *argv[]) { return ret; } + if (!mkdir_ifnot(ROOT_DIR)) { + printf("failed to create root dir: %s\n", ROOT_DIR); + return ret; + } + lm_ctx_init(&ctx); if (!lm_ctx_set_data(&ctx, DATA_DIR)) { @@ -24,6 +29,11 @@ int main(int argc, char *argv[]) { goto end; } + if (!lm_ctx_set_root(&ctx, ROOT_DIR)) { + printf("failed to set root dir: %s (%d)\n", lm_strerror(), lm_error()); + goto end; + } + if (!lm_ctx_database_find(&ctx, &pkg, argv[1], NULL)) { printf("failed to find package: %s (%d)\n", lm_strerror(), lm_error()); goto end; @@ -36,6 +46,8 @@ int main(int argc, char *argv[]) { goto end; } + printf("package check was successful!\n"); + ret = EXIT_SUCCESS; end: diff --git a/locale/tr/LC_MESSAGES/libmp.po b/locale/tr/LC_MESSAGES/libmp.po index f321d97..0b3d653 100644 --- a/locale/tr/LC_MESSAGES/libmp.po +++ b/locale/tr/LC_MESSAGES/libmp.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-07-11 07:30+0300\n" +"POT-Creation-Date: 2024-07-11 07:49+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" diff --git a/src/ctx/check.c b/src/ctx/check.c index 4d1ac39..04941b3 100644 --- a/src/ctx/check.c +++ b/src/ctx/check.c @@ -31,6 +31,8 @@ bool lm_ctx_check(lm_ctx_t *ctx, lm_pkg_t *pkg, lm_ctx_check_callback_t callback join(fp, ctx->root, path); current++; + pdebug(__func__, "(%d/%d) checking %s", current, total, fp); + if(NULL != callback) if(!callback(ctx, pkg, fp, current, total, data)) goto end; diff --git a/src/database/files.c b/src/database/files.c index 6f1c418..c62f6ec 100644 --- a/src/database/files.c +++ b/src/database/files.c @@ -248,13 +248,15 @@ void lm_database_files_next_free(lm_database_t *db, lm_pkg_t *pkg, char **path, return; } - if(NULL != db->files_st) + if(NULL != db->files_st){ sqlite3_finalize(db->files_st); + db->files_st = NULL; + } - if(NULL == *path) + if(NULL != path) free(*path); - if(NULL == *hash) + if(NULL != hash) free(*hash); *keep = false; diff --git a/src/util.c b/src/util.c index f90ab42..284b64a 100644 --- a/src/util.c +++ b/src/util.c @@ -447,6 +447,7 @@ char *get_md5(char *path) { size_t read = 0; alg = EVP_md5(); + ctx = EVP_MD_CTX_new(); bzero(buffer, sizeof(buffer)); bzero(digest, sizeof(digest)); @@ -460,7 +461,7 @@ char *get_md5(char *path) { return NULL; } - while ((read = fread(buffer, sizeof(buffer), 1, file)) > 0) + while ((read = fread(buffer, 1, sizeof(buffer), file)) > 0) EVP_DigestUpdate(ctx, buffer, read); EVP_DigestFinal(ctx, digest, &digest_len); @@ -469,7 +470,8 @@ char *get_md5(char *path) { sum = malloc((digest_len * 2) + 1); for (int i = 0; i < sizeof(digest); i++) - sprintf(&sum[i * 2], "%02x", (unsigned int)digest[i]); + sprintf(&sum[i * 2], "%02x", digest[i]); + fclose(file); return sum; }