From: "PierreGondois" <pierre.gondois@arm.com>
To: Sami Mujawar <sami.mujawar@arm.com>, devel@edk2.groups.io
Subject: Re: [edk2-devel] [PATCH v1 1/1] DynamicTablesPkg: Add SMBIOS String table helper library
Date: Fri, 10 Mar 2023 08:50:30 +0100 [thread overview]
Message-ID: <60da00db-1ddb-0689-8dce-0dc821a3aee8@arm.com> (raw)
In-Reply-To: <8800.1678360288123253286@groups.io>
Hello Sami,
On 3/9/23 12:11, Sami Mujawar wrote:
> 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.
Ok sure, it was just a suggestion.
Also just in case, there was this remark from you:
https://edk2.groups.io/g/devel/message/93654
Otherwise:
Reviewed-by: Pierre Gondois <pierre.gondois@arm.com>
Regards,
Pierre
>
> Please let me know if you think otherwise.
>
> Regards,
>
> Sami Mujawar
prev parent reply other threads:[~2023-03-10 7:50 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 ` [edk2-devel] " Sami Mujawar
2023-03-10 7:50 ` PierreGondois [this message]
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=60da00db-1ddb-0689-8dce-0dc821a3aee8@arm.com \
--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