Fix - MHD version check rework

This commit is contained in:
Michael A Cassaniti
2025-07-01 12:48:21 +10:00
parent 398f2aced3
commit 38c18def10
3 changed files with 37 additions and 32 deletions

View File

@@ -75,9 +75,7 @@
/* Check for libmicrohttp version at runtime
*0.9.69 is the minimum version to prevent loss of special characters in form data (BinAuth and PreAuth)
*/
#define MIN_MHD_MAJOR 0
#define MIN_MHD_MINOR 9
#define MIN_MHD_PATCH 71
#define MIN_MHD_VERSION "0.9.71"
/**
* Remember the thread IDs of threads that simulate wait with pthread_cond_timedwait
@@ -347,40 +345,19 @@ setup_from_config(void)
debug(LOG_INFO, "tmpfs mountpoint is [%s]", config->tmpfsmountpoint);
// Check for libmicrohttp version at runtime, ie actual installed version
int major = 0;
int minor = 0;
int patch = 0;
int outdated = 1;
const char *version = MHD_get_version();
debug(LOG_NOTICE, "MHD version is %s", version);
if (sscanf(version, "%d.%d.%d", &major, &minor, &patch) == 3) {
if (semver_is_outdated(version, MIN_MHD_VERSION)) {
debug(LOG_ERR, "libmicrohttpd is out of date, please upgrade to version %s or higher",
MIN_MHD_VERSION);
if (major >= MIN_MHD_MAJOR) {
outdated = 0;
}
if (outdated == 0 && minor >= MIN_MHD_MINOR) {
outdated = 0;
}
if (outdated == 0 && patch >= MIN_MHD_PATCH) {
outdated = 0;
}
if (outdated == 1) {
debug(LOG_ERR, "libmicrohttpd is out of date, please upgrade to version %d.%d.%d or higher",
MIN_MHD_MAJOR, MIN_MHD_MINOR, MIN_MHD_PATCH);
if (config->use_outdated_mhd == 0) {
debug(LOG_ERR, "exiting...");
exit(1);
} else {
debug(LOG_ERR, "Attempting use of outdated MHD - Data may be corrupted or openNDS may fail...");
}
if (config->use_outdated_mhd == 0) {
debug(LOG_ERR, "exiting...");
exit(1);
} else {
debug(LOG_ERR, "Attempting use of outdated MHD - Data may be corrupted or openNDS may fail...");
}
}

View File

@@ -1438,3 +1438,26 @@ rand16(void)
*/
return( (unsigned short) (rand() >> 15) );
}
int
semver_is_outdated(const char *version, const char *min_version)
{
int major, minor, patch;
int min_major, min_minor, min_patch;
if (sscanf(min_version, "%d.%d.%d", &min_major, &min_minor, &min_patch) != 3) {
debug(LOG_ERR, "BUG: Invalid minimum version format: %s", min_version);
return 1; // assume outdated
}
if (sscanf(version, "%d.%d.%d", &major, &minor, &patch) != 3) {
debug(LOG_ERR, "Invalid version format: %s", version);
return 1; // assume outdated
}
return (
major < min_major ||
(major == min_major && minor < min_minor) ||
(major == min_major && minor == min_minor && patch < min_patch)
);
}

View File

@@ -133,4 +133,9 @@ unsigned short rand16(void);
**/
#define MAX_HOSTPORTLEN ( INET6_ADDRSTRLEN + sizeof("[]:65536")-1 )
/*
* @brief Is the given semantic version outdated?
**/
int semver_is_outdated(const char *version, const char *min_version);
#endif /* _UTIL_H_ */