fix: correct reading for hash function
This commit is contained in:
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user