Message ID | 20210513192036.1692916-1-alex.hung@canonical.com |
---|---|
State | Accepted |
Headers | show |
Series | [1/2] acpi: refactor by fwts_acpi_structure_range_check | expand |
On 13/05/2021 20:20, Alex Hung wrote: > Signed-off-by: Alex Hung <alex.hung@canonical.com> > --- > src/acpi/hmat/hmat.c | 7 +++---- > src/acpi/nfit/nfit.c | 6 ++++++ > src/acpi/pmtt/pmtt.c | 5 +++++ > src/acpi/pptt/pptt.c | 7 +++---- > src/acpi/sdev/sdev.c | 6 ++---- > 5 files changed, 19 insertions(+), 12 deletions(-) > > diff --git a/src/acpi/hmat/hmat.c b/src/acpi/hmat/hmat.c > index 7de8b077..c2efdc93 100644 > --- a/src/acpi/hmat/hmat.c > +++ b/src/acpi/hmat/hmat.c > @@ -199,13 +199,12 @@ static int hmat_test1(fwts_framework *fw) > break; > } > > - if ((offset += entry->length) > table->length) { > + offset += entry->length; > + if (fwts_acpi_structure_range_check(fw, "HMAT", table->length, offset)) { > passed = false; > - fwts_failed(fw, LOG_LEVEL_CRITICAL, > - "HMATBadTableLength", > - "HMAT has more subtypes than its size can handle"); > break; > } > + > entry = (fwts_acpi_table_hmat_header *) (table->data + offset); > fwts_log_nl(fw); > } > diff --git a/src/acpi/nfit/nfit.c b/src/acpi/nfit/nfit.c > index a819fa3e..7e250aba 100644 > --- a/src/acpi/nfit/nfit.c > +++ b/src/acpi/nfit/nfit.c > @@ -516,7 +516,13 @@ static int nfit_test1(fwts_framework *fw) > > fwts_acpi_reserved_zero_check("NFIT", "Reserved", reserved_passed, &passed); > fwts_log_nl(fw); > + > offset += entry->length; > + if (fwts_acpi_structure_range_check(fw, "NFIT", nfit_table->length, offset)) { > + passed = false; > + break; > + } > + > entry = (fwts_acpi_table_nfit_struct_header *)(nfit_table->data + offset); > } > > diff --git a/src/acpi/pmtt/pmtt.c b/src/acpi/pmtt/pmtt.c > index 7cd0952b..74e49717 100644 > --- a/src/acpi/pmtt/pmtt.c > +++ b/src/acpi/pmtt/pmtt.c > @@ -206,6 +206,11 @@ static int pmtt_test1(fwts_framework *fw) > pmtt_memory_device(fw, entry, offset, &passed); > > offset += entry->length; > + if (fwts_acpi_structure_range_check(fw, "PMTT", table->length, offset)) { > + passed = false; > + break; > + } > + > entry = (fwts_acpi_table_pmtt_header *) (table->data + offset); > fwts_log_nl(fw); > } > diff --git a/src/acpi/pptt/pptt.c b/src/acpi/pptt/pptt.c > index 817b0c77..2a4513a6 100644 > --- a/src/acpi/pptt/pptt.c > +++ b/src/acpi/pptt/pptt.c > @@ -163,13 +163,12 @@ static int pptt_test1(fwts_framework *fw) > break; > } > > - if ((offset += entry->length) > table->length) { > + offset += entry->length; > + if (fwts_acpi_structure_range_check(fw, "PPTT", table->length, offset)) { > passed = false; > - fwts_failed(fw, LOG_LEVEL_CRITICAL, > - "PPTTBadTableLength", > - "PPTT has more subtypes than its size can handle"); > break; > } > + > entry = (fwts_acpi_table_pptt_header *) (table->data + offset); > fwts_log_nl(fw); > } > diff --git a/src/acpi/sdev/sdev.c b/src/acpi/sdev/sdev.c > index f03566e8..8946c5e9 100644 > --- a/src/acpi/sdev/sdev.c > +++ b/src/acpi/sdev/sdev.c > @@ -104,11 +104,9 @@ static int sdev_test1(fwts_framework *fw) > break; > } > > - if ((offset += entry->length) > table->length) { > + offset += entry->length; > + if (fwts_acpi_structure_range_check(fw, "SDEV", table->length, offset)) { > passed = false; > - fwts_failed(fw, LOG_LEVEL_CRITICAL, > - "SDEVBadTableLength", > - "SDEV has more subtypes than its size can handle"); > break; > } > > Acked-by: Colin Ian King <colin.king@canonical.com>
On 5/14/21 3:20 AM, Alex Hung wrote: > Signed-off-by: Alex Hung <alex.hung@canonical.com> > --- > src/acpi/hmat/hmat.c | 7 +++---- > src/acpi/nfit/nfit.c | 6 ++++++ > src/acpi/pmtt/pmtt.c | 5 +++++ > src/acpi/pptt/pptt.c | 7 +++---- > src/acpi/sdev/sdev.c | 6 ++---- > 5 files changed, 19 insertions(+), 12 deletions(-) > > diff --git a/src/acpi/hmat/hmat.c b/src/acpi/hmat/hmat.c > index 7de8b077..c2efdc93 100644 > --- a/src/acpi/hmat/hmat.c > +++ b/src/acpi/hmat/hmat.c > @@ -199,13 +199,12 @@ static int hmat_test1(fwts_framework *fw) > break; > } > > - if ((offset += entry->length) > table->length) { > + offset += entry->length; > + if (fwts_acpi_structure_range_check(fw, "HMAT", table->length, offset)) { > passed = false; > - fwts_failed(fw, LOG_LEVEL_CRITICAL, > - "HMATBadTableLength", > - "HMAT has more subtypes than its size can handle"); > break; > } > + > entry = (fwts_acpi_table_hmat_header *) (table->data + offset); > fwts_log_nl(fw); > } > diff --git a/src/acpi/nfit/nfit.c b/src/acpi/nfit/nfit.c > index a819fa3e..7e250aba 100644 > --- a/src/acpi/nfit/nfit.c > +++ b/src/acpi/nfit/nfit.c > @@ -516,7 +516,13 @@ static int nfit_test1(fwts_framework *fw) > > fwts_acpi_reserved_zero_check("NFIT", "Reserved", reserved_passed, &passed); > fwts_log_nl(fw); > + > offset += entry->length; > + if (fwts_acpi_structure_range_check(fw, "NFIT", nfit_table->length, offset)) { > + passed = false; > + break; > + } > + > entry = (fwts_acpi_table_nfit_struct_header *)(nfit_table->data + offset); > } > > diff --git a/src/acpi/pmtt/pmtt.c b/src/acpi/pmtt/pmtt.c > index 7cd0952b..74e49717 100644 > --- a/src/acpi/pmtt/pmtt.c > +++ b/src/acpi/pmtt/pmtt.c > @@ -206,6 +206,11 @@ static int pmtt_test1(fwts_framework *fw) > pmtt_memory_device(fw, entry, offset, &passed); > > offset += entry->length; > + if (fwts_acpi_structure_range_check(fw, "PMTT", table->length, offset)) { > + passed = false; > + break; > + } > + > entry = (fwts_acpi_table_pmtt_header *) (table->data + offset); > fwts_log_nl(fw); > } > diff --git a/src/acpi/pptt/pptt.c b/src/acpi/pptt/pptt.c > index 817b0c77..2a4513a6 100644 > --- a/src/acpi/pptt/pptt.c > +++ b/src/acpi/pptt/pptt.c > @@ -163,13 +163,12 @@ static int pptt_test1(fwts_framework *fw) > break; > } > > - if ((offset += entry->length) > table->length) { > + offset += entry->length; > + if (fwts_acpi_structure_range_check(fw, "PPTT", table->length, offset)) { > passed = false; > - fwts_failed(fw, LOG_LEVEL_CRITICAL, > - "PPTTBadTableLength", > - "PPTT has more subtypes than its size can handle"); > break; > } > + > entry = (fwts_acpi_table_pptt_header *) (table->data + offset); > fwts_log_nl(fw); > } > diff --git a/src/acpi/sdev/sdev.c b/src/acpi/sdev/sdev.c > index f03566e8..8946c5e9 100644 > --- a/src/acpi/sdev/sdev.c > +++ b/src/acpi/sdev/sdev.c > @@ -104,11 +104,9 @@ static int sdev_test1(fwts_framework *fw) > break; > } > > - if ((offset += entry->length) > table->length) { > + offset += entry->length; > + if (fwts_acpi_structure_range_check(fw, "SDEV", table->length, offset)) { > passed = false; > - fwts_failed(fw, LOG_LEVEL_CRITICAL, > - "SDEVBadTableLength", > - "SDEV has more subtypes than its size can handle"); > break; > } > > Acked-by: Ivan Hu <ivan.hu@canonical.com>
diff --git a/src/acpi/hmat/hmat.c b/src/acpi/hmat/hmat.c index 7de8b077..c2efdc93 100644 --- a/src/acpi/hmat/hmat.c +++ b/src/acpi/hmat/hmat.c @@ -199,13 +199,12 @@ static int hmat_test1(fwts_framework *fw) break; } - if ((offset += entry->length) > table->length) { + offset += entry->length; + if (fwts_acpi_structure_range_check(fw, "HMAT", table->length, offset)) { passed = false; - fwts_failed(fw, LOG_LEVEL_CRITICAL, - "HMATBadTableLength", - "HMAT has more subtypes than its size can handle"); break; } + entry = (fwts_acpi_table_hmat_header *) (table->data + offset); fwts_log_nl(fw); } diff --git a/src/acpi/nfit/nfit.c b/src/acpi/nfit/nfit.c index a819fa3e..7e250aba 100644 --- a/src/acpi/nfit/nfit.c +++ b/src/acpi/nfit/nfit.c @@ -516,7 +516,13 @@ static int nfit_test1(fwts_framework *fw) fwts_acpi_reserved_zero_check("NFIT", "Reserved", reserved_passed, &passed); fwts_log_nl(fw); + offset += entry->length; + if (fwts_acpi_structure_range_check(fw, "NFIT", nfit_table->length, offset)) { + passed = false; + break; + } + entry = (fwts_acpi_table_nfit_struct_header *)(nfit_table->data + offset); } diff --git a/src/acpi/pmtt/pmtt.c b/src/acpi/pmtt/pmtt.c index 7cd0952b..74e49717 100644 --- a/src/acpi/pmtt/pmtt.c +++ b/src/acpi/pmtt/pmtt.c @@ -206,6 +206,11 @@ static int pmtt_test1(fwts_framework *fw) pmtt_memory_device(fw, entry, offset, &passed); offset += entry->length; + if (fwts_acpi_structure_range_check(fw, "PMTT", table->length, offset)) { + passed = false; + break; + } + entry = (fwts_acpi_table_pmtt_header *) (table->data + offset); fwts_log_nl(fw); } diff --git a/src/acpi/pptt/pptt.c b/src/acpi/pptt/pptt.c index 817b0c77..2a4513a6 100644 --- a/src/acpi/pptt/pptt.c +++ b/src/acpi/pptt/pptt.c @@ -163,13 +163,12 @@ static int pptt_test1(fwts_framework *fw) break; } - if ((offset += entry->length) > table->length) { + offset += entry->length; + if (fwts_acpi_structure_range_check(fw, "PPTT", table->length, offset)) { passed = false; - fwts_failed(fw, LOG_LEVEL_CRITICAL, - "PPTTBadTableLength", - "PPTT has more subtypes than its size can handle"); break; } + entry = (fwts_acpi_table_pptt_header *) (table->data + offset); fwts_log_nl(fw); } diff --git a/src/acpi/sdev/sdev.c b/src/acpi/sdev/sdev.c index f03566e8..8946c5e9 100644 --- a/src/acpi/sdev/sdev.c +++ b/src/acpi/sdev/sdev.c @@ -104,11 +104,9 @@ static int sdev_test1(fwts_framework *fw) break; } - if ((offset += entry->length) > table->length) { + offset += entry->length; + if (fwts_acpi_structure_range_check(fw, "SDEV", table->length, offset)) { passed = false; - fwts_failed(fw, LOG_LEVEL_CRITICAL, - "SDEVBadTableLength", - "SDEV has more subtypes than its size can handle"); break; }
Signed-off-by: Alex Hung <alex.hung@canonical.com> --- src/acpi/hmat/hmat.c | 7 +++---- src/acpi/nfit/nfit.c | 6 ++++++ src/acpi/pmtt/pmtt.c | 5 +++++ src/acpi/pptt/pptt.c | 7 +++---- src/acpi/sdev/sdev.c | 6 ++---- 5 files changed, 19 insertions(+), 12 deletions(-)