No longer use deprecated MD5() function to get hash

This commit is contained in:
speedie 2023-06-09 21:20:02 +02:00
parent d6df27e839
commit b68666dc6b
3 changed files with 13 additions and 6 deletions

View file

@ -211,8 +211,8 @@ void scaleimage(int *width, int *height) {
void loadimagecache(const char *file, int *width, int *height) { void loadimagecache(const char *file, int *width, int *height) {
int slen = 0, i; int slen = 0, i;
unsigned char digest[MD5_DIGEST_LENGTH]; unsigned int digest_len = EVP_MD_size(EVP_md5());
char md5[MD5_DIGEST_LENGTH*2+1]; unsigned char *digest = (unsigned char *)OPENSSL_malloc(digest_len);
char *xdg_cache, *home = NULL, *dsize, *buf = NULL; char *xdg_cache, *home = NULL, *dsize, *buf = NULL;
struct passwd *pw = NULL; struct passwd *pw = NULL;
@ -249,11 +249,19 @@ void loadimagecache(const char *file, int *width, int *height) {
// calculate md5 from path // calculate md5 from path
sprintf(buf, "file://%s", file); sprintf(buf, "file://%s", file);
MD5((unsigned char*)buf, slen, digest);
EVP_MD_CTX *mdcontext = EVP_MD_CTX_new();
EVP_DigestInit_ex(mdcontext, EVP_md5(), NULL);
EVP_DigestUpdate(mdcontext, buf, slen);
EVP_DigestFinal_ex(mdcontext, digest, &digest_len);
EVP_MD_CTX_free(mdcontext);
free(buf); free(buf);
for(i = 0; i < MD5_DIGEST_LENGTH; ++i) char md5[digest_len*2+1];
for (i = 0; i < digest_len; ++i)
sprintf(&md5[i*2], "%02x", (unsigned int)digest[i]); sprintf(&md5[i*2], "%02x", (unsigned int)digest[i]);
// path for cached thumbnail // path for cached thumbnail

View file

@ -4,7 +4,7 @@
#include <errno.h> #include <errno.h>
#include <pwd.h> #include <pwd.h>
#include <Imlib2.h> #include <Imlib2.h>
#include <openssl/md5.h> #include <openssl/evp.h>
static void setimagesize(int width, int height); static void setimagesize(int width, int height);
static void setimageopts(void); static void setimageopts(void);

View file

@ -31,7 +31,6 @@ build_args = [
'-std=c99', '-std=c99',
'-pedantic', '-pedantic',
'-Wall', '-Wall',
'-Wno-deprecated-declarations',
'-Wno-unused-parameter', '-Wno-unused-parameter',
'-Wno-sign-compare', '-Wno-sign-compare',
] ]