fix version string buffer overflow (#327)

This commit is contained in:
Isaac0-dev 2023-03-27 07:52:13 +10:00 committed by GitHub
parent 01a81fc6f5
commit c22eb8b2ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View File

@ -3,7 +3,7 @@
#include "types.h"
static char sVersionString[MAX_VERSION_LENGTH] = { 0 };
static char sLocalVersionString[MAX_VERSION_LENGTH] = { 0 };
static char sLocalVersionString[MAX_LOCAL_VERSION_LENGTH] = { 0 };
char* get_version(void) {
snprintf(sVersionString, MAX_VERSION_LENGTH, "%s %d.%d", VERSION_TEXT, VERSION_NUMBER, MINOR_VERSION_NUMBER);
@ -11,6 +11,9 @@ char* get_version(void) {
}
char* get_version_local(void) {
if (PATCH_VERSION_NUMBER <= 0) {
return get_version();
}
snprintf(sLocalVersionString, MAX_LOCAL_VERSION_LENGTH, "%s %d.%d.%d", VERSION_TEXT, VERSION_NUMBER, MINOR_VERSION_NUMBER, PATCH_VERSION_NUMBER);
return sLocalVersionString;
}

View File

@ -4,10 +4,10 @@
#define VERSION_TEXT "beta"
#define VERSION_NUMBER 32
#define MINOR_VERSION_NUMBER 0
#define PATCH_VERSION_NUMBER 2
#define PATCH_VERSION_NUMBER 3
#define MAX_VERSION_LENGTH 10
#define MAX_LOCAL_VERSION_LENGTH 12
#define MAX_LOCAL_VERSION_LENGTH 11
char* get_version(void);
char* get_version_local(void);