summaryrefslogtreecommitdiff
path: root/source/tools/acpixtract/acpixtract.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/tools/acpixtract/acpixtract.c')
-rw-r--r--source/tools/acpixtract/acpixtract.c102
1 files changed, 94 insertions, 8 deletions
diff --git a/source/tools/acpixtract/acpixtract.c b/source/tools/acpixtract/acpixtract.c
index b6cb4d0766b58..e0d17556f709c 100644
--- a/source/tools/acpixtract/acpixtract.c
+++ b/source/tools/acpixtract/acpixtract.c
@@ -44,6 +44,13 @@
#include "acpixtract.h"
+/* Local prototypes */
+
+static BOOLEAN
+AxIsFileAscii (
+ FILE *Handle);
+
+
/******************************************************************************
*
* FUNCTION: AxExtractTables
@@ -72,7 +79,8 @@ AxExtractTables (
unsigned int FoundTable = 0;
unsigned int Instances = 0;
unsigned int ThisInstance;
- char ThisSignature[4];
+ char ThisSignature[5];
+ char UpperSignature[5];
int Status = 0;
unsigned int State = AX_STATE_FIND_HEADER;
@@ -86,17 +94,27 @@ AxExtractTables (
return (-1);
}
+ if (!AxIsFileAscii (InputFile))
+ {
+ fclose (InputFile);
+ return (-1);
+ }
+
if (Signature)
{
+ strncpy (UpperSignature, Signature, 4);
+ UpperSignature[4] = 0;
+ AcpiUtStrupr (UpperSignature);
+
/* Are there enough instances of the table to continue? */
- AxNormalizeSignature (Signature);
+ AxNormalizeSignature (UpperSignature);
- Instances = AxCountTableInstances (InputPathname, Signature);
+ Instances = AxCountTableInstances (InputPathname, UpperSignature);
if (Instances < MinimumInstances)
{
printf ("Table [%s] was not found in %s\n",
- Signature, InputPathname);
+ UpperSignature, InputPathname);
fclose (InputFile);
return (-1);
}
@@ -126,7 +144,7 @@ AxExtractTables (
{
/* Ignore signatures that don't match */
- if (!ACPI_COMPARE_NAME (ThisSignature, Signature))
+ if (!ACPI_COMPARE_NAME (ThisSignature, UpperSignature))
{
continue;
}
@@ -205,8 +223,7 @@ AxExtractTables (
if (!FoundTable)
{
- printf ("Table [%s] was not found in %s\n",
- Signature, InputPathname);
+ printf ("No ACPI tables were found in %s\n", InputPathname);
}
@@ -276,6 +293,12 @@ AxExtractToMultiAmlFile (
return (-1);
}
+ if (!AxIsFileAscii (InputFile))
+ {
+ fclose (InputFile);
+ return (-1);
+ }
+
/* Open the output file in binary mode */
OutputFile = fopen (Gbl_OutputFilename, "w+b");
@@ -401,6 +424,12 @@ AxListTables (
return (-1);
}
+ if (!AxIsFileAscii (InputFile))
+ {
+ fclose (InputFile);
+ return (-1);
+ }
+
/* Dump the headers for all tables found in the input file */
printf ("\nSignature Length Revision OemId OemTableId"
@@ -442,6 +471,11 @@ AxListTables (
continue;
}
+ if (!AcpiIsValidSignature (TableHeader->Signature))
+ {
+ continue;
+ }
+
/* Signature and Table length */
Gbl_TableCount++;
@@ -470,7 +504,59 @@ AxListTables (
TableHeader->AslCompilerId, TableHeader->AslCompilerRevision);
}
- printf ("\nFound %u ACPI tables\n", Gbl_TableCount);
+ printf ("\nFound %u ACPI tables in %s\n", Gbl_TableCount, InputPathname);
fclose (InputFile);
return (0);
}
+
+
+/*******************************************************************************
+ *
+ * FUNCTION: AxIsFileAscii
+ *
+ * PARAMETERS: Handle - To open input file
+ *
+ * RETURN: TRUE if file is entirely ASCII and printable
+ *
+ * DESCRIPTION: Verify that the input file is entirely ASCII.
+ *
+ ******************************************************************************/
+
+static BOOLEAN
+AxIsFileAscii (
+ FILE *Handle)
+{
+ UINT8 Byte;
+
+
+ /* Read the entire file */
+
+ while (fread (&Byte, 1, 1, Handle) == 1)
+ {
+ /* Check for an ASCII character */
+
+ if (!ACPI_IS_ASCII (Byte))
+ {
+ goto ErrorExit;
+ }
+
+ /* Ensure character is either printable or a "space" char */
+
+ else if (!isprint (Byte) && !isspace (Byte))
+ {
+ goto ErrorExit;
+ }
+ }
+
+ /* File is OK (100% ASCII) */
+
+ fseek (Handle, 0, SEEK_SET);
+ return (TRUE);
+
+ErrorExit:
+
+ printf ("File is binary (contains non-text or non-ascii characters)\n");
+ fseek (Handle, 0, SEEK_SET);
+ return (FALSE);
+
+}