Fix possible segfault

This commit is contained in:
Linus Dierheimer
2022-09-04 13:56:14 +02:00
parent 6d0675820e
commit df0e13b198
3 changed files with 10 additions and 6 deletions
+6
View File
@@ -26,6 +26,12 @@ void ffDetectOSImpl(FFOSResult* os, const FFinstance* instance)
ffStrbufInit(&os->buildID);
ffSettingsGetAndroidProperty("ro.build.id", &os->buildID);
ffStrbufInit(&os->systemName);
ffStrbufSetS(&os->systemName, instance->state.utsname.sysname);
ffStrbufInit(&os->architecture);
ffStrbufSetS(&os->architecture, instance->state.utsname.machine);
ffStrbufInitA(&os->idLike, 0);
ffStrbufInitA(&os->variant, 0);
ffStrbufInitA(&os->variantID, 0);
+1 -1
View File
@@ -128,7 +128,6 @@ static void detectOS(FFOSResult* os, const FFinstance* instance)
void ffDetectOSImpl(FFOSResult* os, const FFinstance* instance)
{
ffStrbufInit(&os->systemName);
ffStrbufInit(&os->name);
ffStrbufInit(&os->prettyName);
ffStrbufInit(&os->id);
@@ -139,6 +138,7 @@ void ffDetectOSImpl(FFOSResult* os, const FFinstance* instance)
ffStrbufInit(&os->versionID);
ffStrbufInit(&os->codename);
ffStrbufInit(&os->buildID);
ffStrbufInit(&os->systemName);
ffStrbufInit(&os->architecture);
ffStrbufSetS(&os->systemName, instance->state.utsname.sysname);
+3 -5
View File
@@ -13,13 +13,11 @@ static void buildOutputDefault(const FFOSResult* os, FFstrbuf* result)
if(os->name.length > 0)
ffStrbufAppend(result, &os->name);
else if(os->prettyName.length > 0)
ffStrbufAppend(result, &os->name);
ffStrbufAppend(result, &os->prettyName);
else if(os->id.length > 0)
ffStrbufAppend(result, &os->id);
else if(os->systemName.length > 0)
ffStrbufAppend(result, &os->systemName);
else
ffStrbufAppendS(result, "Linux");
ffStrbufAppend(result, &os->systemName);
//Append version if it is missing
if(os->versionID.length > 0 && ffStrbufFirstIndex(result, &os->versionID) == result->length)
@@ -84,7 +82,7 @@ void ffPrintOS(FFinstance* instance)
{
const FFOSResult* os = ffDetectOS(instance);
if(os->name.length == 0 && os->prettyName.length == 0)
if(os->name.length == 0 && os->prettyName.length == 0 && os->id.length == 0 && os->systemName.length == 0)
{
ffPrintError(instance, FF_OS_MODULE_NAME, 0, &instance->config.os, "Could not detect OS");
return;