diff --git a/src/common/FFstrbuf.h b/src/common/FFstrbuf.h index 59497b56e..6c194687f 100644 --- a/src/common/FFstrbuf.h +++ b/src/common/FFstrbuf.h @@ -230,6 +230,7 @@ static inline void ffStrbufInitMoveS(FFstrbuf* strbuf, char* heapStr) ffStrbufInitMoveNS(strbuf, (uint32_t) strlen(heapStr), heapStr); } +// Despite the name, this function resets strbuf to the initial/unallocated state static inline void ffStrbufDestroy(FFstrbuf* strbuf) { if(strbuf->allocated > 0) diff --git a/src/common/impl/smbiosHelper.c b/src/common/impl/smbiosHelper.c index 34e98a80f..a41638ccb 100644 --- a/src/common/impl/smbiosHelper.c +++ b/src/common/impl/smbiosHelper.c @@ -161,15 +161,27 @@ static bool parseSmbiosTable(const uint8_t* data, uint32_t length) #ifdef __linux__ bool ffGetSmbiosValue(const char* devicesPath, const char* classPath, FFstrbuf* buffer) { - if (ffReadFileBuffer(devicesPath, buffer)) + // /sys/class/dmi/id/* are all pseudo-files with very small content + // so reading the whole file at once is efficient + ffStrbufEnsureFixedLengthFree(buffer, 127); + + ssize_t len = ffReadFileData(devicesPath, buffer->allocated - 1, buffer->chars); + if (len > 0) { + assert(len < buffer->allocated); + buffer->chars[len] = '\0'; + buffer->length = (uint32_t) len; ffStrbufTrimRightSpace(buffer); if(ffIsSmbiosValueSet(buffer)) return true; } - if (ffReadFileBuffer(classPath, buffer)) + len = ffReadFileData(classPath, buffer->allocated - 1, buffer->chars); + if (len > 0) { + assert(len < buffer->allocated); + buffer->chars[len] = '\0'; + buffer->length = (uint32_t) len; ffStrbufTrimRightSpace(buffer); if(ffIsSmbiosValueSet(buffer)) return true;