Remove trailing spaces from SMBIOS strings, as they cause UI glitches

In particular, About Memory window starts to repeat PartNumber multiple times
This commit is contained in:
vit9696 2019-03-06 23:29:06 +03:00
parent 30c053ad1c
commit c419f7bc93
5 changed files with 19 additions and 96 deletions

2
.gitignore vendored
View File

@ -9,3 +9,5 @@ DICT
fuzz-*.log
crash-*
oom-*
out.bin

View File

@ -107,13 +107,10 @@ UINT8
SmbiosOverrideString (
IN OC_SMBIOS_TABLE *Table,
IN CONST CHAR8 *Override OPTIONAL,
IN UINT8 *Index,
IN BOOLEAN Hex
IN UINT8 *Index
)
{
UINT32 Length;
UINT32 ByteLength;
UINT32 MaxLength;
//
// No override.
@ -122,36 +119,30 @@ SmbiosOverrideString (
return 0;
}
//
// In hex format each string is prefixed with 0x and each char becomes two.
//
MaxLength = Hex ? SMBIOS_STRING_MAX_LENGTH / 2 - SMBIOS_STRING_HEX_PREFIX_SIZE : SMBIOS_STRING_MAX_LENGTH;
Length = (UINT32) AsciiStrLen (Override);
//
// Truncate to fit but do not error.
//
if (Length > MaxLength) {
Length = MaxLength;
DEBUG ((DEBUG_INFO, "SMBIOS truncating '%a' to %u bytes for hex %d\n", Override, Length, Hex));
if (Length > SMBIOS_STRING_MAX_LENGTH) {
Length = SMBIOS_STRING_MAX_LENGTH;
DEBUG ((DEBUG_INFO, "SMBIOS truncating '%a' to %u bytes for safe %d\n", Override, Length, Safe));
}
while (Length > 0 && Override[Length - 1] == ' ') {
Length--;
}
if (Length == 0) {
return 0;
}
ByteLength = Hex ? Length * 2 + SMBIOS_STRING_HEX_PREFIX_SIZE + 1 : Length + 1;
if (EFI_ERROR (SmbiosExtendTable (Table, ByteLength))) {
DEBUG ((DEBUG_WARN, "SMBIOS failed to write '%a' with %u byte extension\n", Override, ByteLength));
if (EFI_ERROR (SmbiosExtendTable (Table, Length + 1))) {
DEBUG ((DEBUG_WARN, "SMBIOS failed to write '%a' with %u byte extension\n", Override, Length + 1));
return 0;
}
if (Hex) {
return SmbiosSetStringHex (&Table->CurrentStrPtr, Override, Length, Index);
}
return SmbiosSetString (&Table->CurrentStrPtr, Override, Length, Index);
return SmbiosSetString (&Table->CurrentStrPtr, Override, Length, Index, Safe);
}
STATIC
@ -442,49 +433,15 @@ SmbiosSetString (
ASSERT (Buffer != NULL);
ASSERT (String != NULL);
ASSERT (Index != NULL);
ASSERT (Length > 0);
if (Length > 0) {
CopyMem (*Buffer, String, Length);
}
CopyMem (*Buffer, String, Length);
*Buffer += Length + 1;
(*Index)++;
return *Index;
}
UINT8
SmbiosSetStringHex (
IN OUT CHAR8 **Buffer,
IN CONST CHAR8 *String,
IN UINT32 Length,
IN OUT UINT8 *Index
)
{
CHAR8 *Target;
UINT8 Byte;
Target = *Buffer;
if (Length > 0) {
*Target++ = '0';
*Target++ = 'x';
while (Length > 0) {
Byte = (UINT8) (*String++);
*Target++ = "0123456789ABCDEF"[((Byte >> 4U) & 0xFU)];
*Target++ = "0123456789ABCDEF"[(Byte & 0xFU)];
Length--;
}
}
*Buffer = Target + 1;
(*Index)++;
return *Index;
}
UINT32
SmbiosGetStructureLength (
IN APPLE_SMBIOS_STRUCTURE_POINTER SmbiosTable,

View File

@ -23,16 +23,6 @@
//
#define SMBIOS_STRUCTURE_TERMINATOR_SIZE 2
//
// 0x prefix size in SMBIOS strings in hex mode.
//
#define SMBIOS_STRING_HEX_PREFIX_SIZE 2
//
// 0x prefix size in SMBIOS strings in hex mode.
//
#define SMBIOS_ENTRY_POINT_CHECKSUM_SIZE 16U
//
// According to SMBIOS spec (3.2.0, page 26) SMBIOS handle is a number from 0 to 0xFF00.
// SMBIOS spec does not require handles to be contiguous or remain valid across SMBIOS.
@ -170,7 +160,7 @@ SmbiosTableFree (
@param[in, out] Table Current table buffer.
@param[in] Override String data override.
@param[in, out] Index Pointer to current string index, incremented on success.
@param[in] Hex Write in hex format.
@param[in] Safe Filter certain characters.
@retval assigned string index or 0
**/
@ -178,8 +168,7 @@ UINT8
SmbiosOverrideString (
IN OUT OC_SMBIOS_TABLE *Table,
IN CONST CHAR8 *Override OPTIONAL,
IN OUT UINT8 *Index,
IN BOOLEAN Hex
IN OUT UINT8 *Index
);
/**
@ -245,24 +234,6 @@ SmbiosSetString (
IN OUT UINT8 *Index
);
/**
Write string to SMBIOS structure in hex format
@param[in, out] Buffer Pointer to location containing the current address within the buffer.
@param[in] String Buffer containing the null terminated ascii string.
@param[in] Length String length to write.
@param[in, out] Index Pointer to current string index, incremented on success.
@retval assigned string index or 0
**/
UINT8
SmbiosSetStringHex (
IN OUT CHAR8 **Buffer,
IN CONST CHAR8 *String,
IN UINT32 Length,
IN OUT UINT8 *Index
);
/**
Obtain and validate structure length.

View File

@ -45,7 +45,7 @@ STATIC SMBIOS_TABLE_3_0_ENTRY_POINT *mOriginalSmbios3;
STATIC APPLE_SMBIOS_STRUCTURE_POINTER mOriginalTable;
STATIC UINT32 mOriginalTableSize;
#define SMBIOS_OVERRIDE_STR(Table, Field, Original, Value, Index, Fallback, Hex) \
#define SMBIOS_OVERRIDE_S(Table, Field, Original, Value, Index, Fallback) \
do { \
CONST CHAR8 *RealValue__ = (Value); \
if (RealValue__ == NULL && ((Original).Raw) != NULL && (Original).Raw + (Original).Standard.Hdr->Length \
@ -55,17 +55,10 @@ STATIC UINT32 mOriginalTableSize;
(((Table)->CurrentPtr).Field) = SmbiosOverrideString ( \
(Table), \
RealValue__ != NULL ? RealValue__ : (Fallback), \
(Index), \
(Hex) \
(Index) \
); \
} while (0)
#define SMBIOS_OVERRIDE_S(Table, Field, Original, Value, Index, Fallback) \
SMBIOS_OVERRIDE_STR ((Table), Field, (Original), (Value), (Index), (Fallback), FALSE)
#define SMBIOS_OVERRIDE_H(Table, Field, Original, Value, Index, Fallback) \
SMBIOS_OVERRIDE_STR ((Table), Field, (Original), (Value), (Index), (Fallback), TRUE)
#define SMBIOS_OVERRIDE_V(Table, Field, Original, Value, Fallback) \
do { \
if ((Value) != NULL) { \

Binary file not shown.