public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Sami Mujawar" <sami.mujawar@arm.com>
To: PierreGondois <pierre.gondois@arm.com>,devel@edk2.groups.io
Subject: Re: [edk2-devel] [PATCH v1 1/1] DynamicTablesPkg: Add SMBIOS String table helper library
Date: Thu, 09 Mar 2023 03:11:28 -0800	[thread overview]
Message-ID: <8800.1678360288123253286@groups.io> (raw)
In-Reply-To: <61170181-b9e3-cb57-a439-47f0d816bf04@arm.com>

[-- Attachment #1: Type: text/plain, Size: 3236 bytes --]

Hi Pierre,

On Tue, Oct 4, 2022 at 01:22 AM, PierreGondois wrote:

> 
> 
>> 
>>> +EFI_STATUS
>>> +EFIAPI
>>> +StringTablePublishStringSet (
>>> + IN STRING_TABLE *CONST StrTable,
>>> + IN CHAR8 *CONST SmbiosStringAreaStart,
>>> + IN CONST UINTN SmbiosStringAreaSize
>>> + )
>>> +{
>>> + UINT8 Index;
>>> + STRING_ELEMENT *StrElement;
>>> + CHAR8 *SmbiosString;
>>> + UINTN BytesRemaining;
>>> + UINTN BytesCopied;
>>> +
>>> + if ((StrTable == NULL) || (SmbiosStringAreaStart == NULL)) {
>>> + return EFI_INVALID_PARAMETER;
>>> + }
>>> +
>>> + if (SmbiosStringAreaSize < StringTableGetStringSetSize (StrTable)) {
>>> + return EFI_BUFFER_TOO_SMALL;
>>> + }
>>> +
>>> + SmbiosString = SmbiosStringAreaStart;
>>> + BytesRemaining = SmbiosStringAreaSize;
>>> +
>>> + if (StrTable->StrCount == 0) {
>>> + // See Section 6.1.3 Text strings, SMBIOS Specification Version 3.6.0
>>> + // If the formatted portion of the structure contains string-reference
>>> + // fields and all the string fields are set to 0 (no string references),
>>> 
>>> + // the formatted section of the structure is followed by two null (00h)
>>> + // BYTES.
>>> + *SmbiosString++ = '\0';
>>> + } else {
>>> + for (Index = 0; Index < StrTable->StrCount; Index++) {
>>> + StrElement = &StrTable->Elements[Index];
>>> + AsciiStrCpyS (SmbiosString, BytesRemaining, StrElement->String);
>>> +
>>> + // See Section 6.1.3 Text strings, SMBIOS Specification Version 3.6.0
>>> + // - Each string is terminated with a null (00h) BYTE
>>> + // Bytes Copied = String length + 1 for the string NULL terminator.
>>> + BytesCopied = StrElement->StringLen + 1;
>>> + BytesRemaining -= BytesCopied;
>>> + SmbiosString += BytesCopied;
>>> + }
>>> + }
>>> +
>>> + // See Section 6.1.3 Text strings, SMBIOS Specification Version 3.6.0
>>> + // - the set of strings is terminated with an additional null (00h)
>>> BYTE.
>>> + *SmbiosString = '\0';
>> 
>> [GM] Shouldn't you advance the SmbiosString pointer by one more ? After
>> the loop isn't SmbiosString going to be at the NULL char of the last
>> string ? And we're trying to add one more NULL character ?
>> Should it be:
>> SmbiosString++;
>> *SmbiosString = '\0';
> 
> I didn't try to run the code, but it seems ok to me. Assuming the string
> has 9 chars:
> """
> // Copy 9 chars + 1 NULL char
> AsciiStrCpyS (SmbiosString, BytesRemaining, StrElement->String);
> 
> // We have copied 10 chars
> BytesCopied = StrElement->StringLen + 1;
> BytesRemaining -= BytesCopied;
> // Increment SmbiosString of 10 chars, so SmbiosString is pointing
> // to an un-initialized char now and we can continue.
> SmbiosString += BytesCopied;
> """
> 
> However, maybe we need to add an extra check/ASSERT for BytesRemaining
> before
> writing the last NULL char.

The check at the function entry i.e. "if (SmbiosStringAreaSize < StringTableGetStringSetSize (StrTable)) {"
should cover this, as BytesRemaining is derived from SmbiosStringAreaSize.
So as long as StringTableGetStringSetSize() returns the correct size, the additional check before writing
the last NULL char is not needed.

Please let me know if you think otherwise.

Regards,

Sami Mujawar

[-- Attachment #2: Type: text/html, Size: 3381 bytes --]

  reply	other threads:[~2023-03-09 11:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-12 14:18 [PATCH v1 1/1] DynamicTablesPkg: Add SMBIOS String table helper library Sami Mujawar
2022-09-12 15:02 ` Sami Mujawar
2022-09-13  3:24 ` [edk2-devel] " Chang, Abner
2022-10-04  3:01 ` Girish Mahadevan
2022-10-04  8:16   ` Sami Mujawar
2022-10-04 14:38     ` Girish Mahadevan
2022-10-04  8:21   ` PierreGondois
2023-03-09 11:11     ` Sami Mujawar [this message]
2023-03-10  7:50       ` [edk2-devel] " PierreGondois

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8800.1678360288123253286@groups.io \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox