ACK: [PATCH] lib: fwts_acpi_tables: fix segfault when tables fail to load (LP: #1452201)
Alex Hung
alex.hung at canonical.com
Tue Dec 15 15:05:28 UTC 2015
On 2015-12-15 05:37 PM, Colin King wrote:
> From: Colin Ian King <colin.king at canonical.com>
>
> Running any ACPI table related test on a ppc64le will trigger a segfault
> because ACPI tables cannot be loaded from memory, from /sys/firmware or
> from file. There are a few tidy-ups that need to be fixed to avoid this
> situation:
>
> 1. fwts_acpi_load_tables_from_file_generic must check that the path
> provided is not null
> 2. it also needs to account for tables that are valid rather than
> total count of files found in the directory being scanned for ACPI
> tables
> 3. fwts_acpi_load_tables_from_file also musg check that the
> fw->acpi_table_path is not null before trying to load tables from
> this path
>
> Signed-off-by: Colin Ian King <colin.king at canonical.com>
> ---
> src/lib/src/fwts_acpi_tables.c | 17 ++++++++++++-----
> 1 file changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/src/lib/src/fwts_acpi_tables.c b/src/lib/src/fwts_acpi_tables.c
> index 56f4c6b..42aefcc 100644
> --- a/src/lib/src/fwts_acpi_tables.c
> +++ b/src/lib/src/fwts_acpi_tables.c
> @@ -772,19 +772,21 @@ static int fwts_acpi_load_tables_from_file_generic(
> int *count)
> {
> struct dirent **dir_entries;
> - int i;
> + int i, n;
> +
> + *count = 0;
> + if (!acpi_table_path)
> + return FWTS_ERROR;
>
> /*
> * Read in directory in alphabetical name sorted order
> * to ensure the tables are always loaded into memory
> * in some form of deterministic order
> */
> - if ((*count = scandir(acpi_table_path, &dir_entries, 0, alphasort)) < 0) {
> - *count = 0;
> + if ((n = scandir(acpi_table_path, &dir_entries, 0, alphasort)) < 0)
> return FWTS_ERROR;
> - }
>
> - for (i = 0; i < *count; i++) {
> + for (i = 0; i < n; i++) {
> /* Ignore . directories */
> if (dir_entries[i]->d_name[0] == '.')
> continue;
> @@ -829,6 +831,8 @@ static int fwts_acpi_load_tables_from_file_generic(
> name[4] = '\0';
> }
>
> + (*count)++;
> +
> if (!strncmp(name, "XSDT", 4) || !strncmp(name, "RSDT", 4)) {
> /*
> * For XSDT and RSDT we don't bother loading at this point.
> @@ -866,6 +870,9 @@ static int fwts_acpi_load_tables_from_file(fwts_framework *fw)
> {
> int count;
>
> + if (!fw->acpi_table_path)
> + return FWTS_ERROR;
> +
> fwts_acpi_load_tables_from_file_generic(fw, fw->acpi_table_path, ".dat", &count);
> if (count == 0) {
> fwts_log_error(fw, "Could not find any APCI tables in directory '%s'.\n", fw->acpi_table_path);
>
Acked-by: Alex Hung <alex.hung at canonical.com>
More information about the fwts-devel
mailing list