[acpica] Avoid undefined behavior
Upstream:
- https://github.com/acpica/acpica/pull/995.
Bug: 42084914
Change-Id: I1ef5d449d2cdbf9f09a3a9fdbded852b8afefdb3
diff --git a/source/components/resources/rsaddr.c b/source/components/resources/rsaddr.c
index 1c4b7ec..f9581ca 100644
--- a/source/components/resources/rsaddr.c
+++ b/source/components/resources/rsaddr.c
@@ -323,17 +323,12 @@
ACPI_RESOURCE *Resource,
AML_RESOURCE *Aml)
{
- /* Avoid undefined behavior: member access within misaligned address */
-
- AML_RESOURCE_ADDRESS Address;
- memcpy(&Address, Aml, sizeof(Address));
-
ACPI_FUNCTION_ENTRY();
/* Validate the Resource Type */
- if ((Address.ResourceType > 2) &&
- (Address.ResourceType < 0xC0))
+ if ((Aml->Address.ResourceType > 2) &&
+ (Aml->Address.ResourceType < 0xC0))
{
return (FALSE);
}
@@ -360,7 +355,7 @@
/* Generic resource type, just grab the TypeSpecific byte */
Resource->Data.Address.Info.TypeSpecific =
- Address.SpecificFlags;
+ Aml->Address.SpecificFlags;
}
return (TRUE);
@@ -388,7 +383,6 @@
{
ACPI_FUNCTION_ENTRY ();
-
/* Set the Resource Type and General Flags */
(void) AcpiRsConvertResourceToAml (
diff --git a/source/components/resources/rscalc.c b/source/components/resources/rscalc.c
index 32e498f..b08fb6f 100644
--- a/source/components/resources/rscalc.c
+++ b/source/components/resources/rscalc.c
@@ -633,15 +633,11 @@
break;
case ACPI_RESOURCE_NAME_SERIAL_BUS: {
- /* Avoid undefined behavior: member access within misaligned address */
-
- AML_RESOURCE_COMMON_SERIALBUS CommonSerialBus;
- memcpy(&CommonSerialBus, AmlResource, sizeof(CommonSerialBus));
MinimumAmlResourceLength = AcpiGbl_ResourceAmlSerialBusSizes[
- CommonSerialBus.Type];
+ AmlResource->CommonSerialBus.Type];
ExtraStructBytes +=
- CommonSerialBus.ResourceLength -
+ AmlResource->CommonSerialBus.ResourceLength -
MinimumAmlResourceLength;
break;
}
@@ -713,13 +709,8 @@
if (AcpiUtGetResourceType (AmlBuffer) ==
ACPI_RESOURCE_NAME_SERIAL_BUS)
{
- /* Avoid undefined behavior: member access within misaligned address */
-
- AML_RESOURCE_COMMON_SERIALBUS CommonSerialBus;
- memcpy(&CommonSerialBus, AmlResource, sizeof(CommonSerialBus));
-
BufferSize = AcpiGbl_ResourceStructSerialBusSizes[
- CommonSerialBus.Type] + ExtraStructBytes;
+ AmlResource->CommonSerialBus.Type] + ExtraStructBytes;
}
else
{
diff --git a/source/components/resources/rslist.c b/source/components/resources/rslist.c
index 85c40b2..b59cc92 100644
--- a/source/components/resources/rslist.c
+++ b/source/components/resources/rslist.c
@@ -101,12 +101,7 @@
if (AcpiUtGetResourceType (Aml) ==
ACPI_RESOURCE_NAME_SERIAL_BUS)
{
- /* Avoid undefined behavior: member access within misaligned address */
-
- AML_RESOURCE_COMMON_SERIALBUS CommonSerialBus;
- memcpy(&CommonSerialBus, AmlResource, sizeof(CommonSerialBus));
-
- if (CommonSerialBus.Type >
+ if (AmlResource->CommonSerialBus.Type >
AML_RESOURCE_MAX_SERIALBUSTYPE)
{
ConversionTable = NULL;
@@ -116,7 +111,7 @@
/* This is an I2C, SPI, UART, or CSI2 SerialBus descriptor */
ConversionTable = AcpiGbl_ConvertResourceSerialBusDispatch [
- CommonSerialBus.Type];
+ AmlResource->CommonSerialBus.Type];
}
}
else
diff --git a/source/components/utilities/utresrc.c b/source/components/utilities/utresrc.c
index dc70b82..dd425dc 100644
--- a/source/components/utilities/utresrc.c
+++ b/source/components/utilities/utresrc.c
@@ -424,21 +424,16 @@
AmlResource = ACPI_CAST_PTR (AML_RESOURCE, Aml);
if (ResourceType == ACPI_RESOURCE_NAME_SERIAL_BUS)
{
- /* Avoid undefined behavior: member access within misaligned address */
-
- AML_RESOURCE_COMMON_SERIALBUS CommonSerialBus;
- memcpy(&CommonSerialBus, AmlResource, sizeof(CommonSerialBus));
-
/* Validate the BusType field */
- if ((CommonSerialBus.Type == 0) ||
- (CommonSerialBus.Type > AML_RESOURCE_MAX_SERIALBUSTYPE))
+ if ((AmlResource->CommonSerialBus.Type == 0) ||
+ (AmlResource->CommonSerialBus.Type > AML_RESOURCE_MAX_SERIALBUSTYPE))
{
if (WalkState)
{
ACPI_ERROR ((AE_INFO,
"Invalid/unsupported SerialBus resource descriptor: BusType 0x%2.2X",
- CommonSerialBus.Type));
+ AmlResource->CommonSerialBus.Type));
}
return (AE_AML_INVALID_RESOURCE_TYPE);
}
diff --git a/source/include/amlresrc.h b/source/include/amlresrc.h
index 4b62301..e9ce04f 100644
--- a/source/include/amlresrc.h
+++ b/source/include/amlresrc.h
@@ -684,10 +684,6 @@
#define AML_RESOURCE_PIN_GROUP_CONFIG_REVISION 1 /* ACPI 6.2 */
-/* restore default alignment */
-
-#pragma pack()
-
/* Union of all resource descriptors, so we can allocate the worst case */
typedef union aml_resource
@@ -744,6 +740,9 @@
} AML_RESOURCE;
+/* restore default alignment */
+
+#pragma pack()
/* Interfaces used by both the disassembler and compiler */