+ return FALSE;
+ }
+}
+
+static char buf[BUFSIZE];
+static char address[BUFSIZE];
+static char name[BUFSIZE];
+
+/* Return number of symbols in a symbol-table file. */
+
+static unsigned int
+num_of_syms_in (FILE * f)
+{
+ char type;
+ unsigned int num = 0;
+
+ while (!feof (f) && fgets (buf, BUFSIZE - 1, f))
+ {
+ if (sscanf (buf, "%" STR_BUFSIZE "s %c %" STR_BUFSIZE "s", address, &type, name) == 3)
+ if (type == 't' || type == 'T')
+ {
+ /* PR 20499 - prevent integer overflow computing argument to xmalloc. */
+ if (++num >= UINT_MAX / sizeof (Sym))
+ return -1U;
+ }
+ }
+
+ return num;
+}
+
+/* Read symbol table from a file. */
+
+void
+core_create_syms_from (const char * sym_table_file)
+{
+ char type;
+ bfd_vma min_vma = ~(bfd_vma) 0;
+ bfd_vma max_vma = 0;
+ FILE * f;
+
+ f = fopen (sym_table_file, "r");
+ if (!f)
+ {
+ fprintf (stderr, _("%s: could not open %s.\n"), whoami, sym_table_file);
+ done (1);
+ }
+
+ /* Pass 1 - determine upper bound on number of function names. */
+ symtab.len = num_of_syms_in (f);
+
+ if (symtab.len == 0)
+ {
+ fprintf (stderr, _("%s: file `%s' has no symbols\n"), whoami, sym_table_file);
+ done (1);
+ }
+ else if (symtab.len == -1U)
+ {
+ fprintf (stderr, _("%s: file `%s' has too many symbols\n"),
+ whoami, sym_table_file);
+ done (1);
+ }
+
+ symtab.base = (Sym *) xmalloc (symtab.len * sizeof (Sym));
+
+ /* Pass 2 - create symbols. */
+ symtab.limit = symtab.base;
+
+ if (fseek (f, 0, SEEK_SET) != 0)
+ {
+ perror (sym_table_file);
+ done (1);