From: Jim Kingdon Date: Mon, 26 Apr 1993 21:03:35 +0000 (+0000) Subject: * trad-core.c (trad_unix_core_file_p): Check the file size. X-Git-Tag: gdb-4_18~19438 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=31568a6f4188b24e173dc22c02dbf9b3d85dd402;p=external%2Fbinutils.git * trad-core.c (trad_unix_core_file_p): Check the file size. --- diff --git a/bfd/ChangeLog b/bfd/ChangeLog index c0380e3..0d9977b 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,11 @@ +Mon Apr 26 13:55:42 1993 Jim Kingdon (kingdon@cygnus.com) + + * trad-core.c (trad_unix_core_file_p): Check the file size. + +Mon Apr 26 13:24:43 1993 Steve Chamberlain (sac@thepub.cygnus.com) + + * coff-alpha.c: Remove duplicate function and add warnings. + Mon Apr 26 11:25:58 1993 Ian Lance Taylor (ian@cygnus.com) * sco-core.c (sco_core_vec): Add initializers for new target diff --git a/bfd/trad-core.c b/bfd/trad-core.c index 1ae1e2f..e3af10d 100644 --- a/bfd/trad-core.c +++ b/bfd/trad-core.c @@ -76,14 +76,48 @@ trad_unix_core_file_p (abfd) val = bfd_read ((void *)&u, 1, sizeof u, abfd); if (val != sizeof u) - return 0; /* Too small to be a core file */ + { + /* Too small to be a core file */ + bfd_error = wrong_format; + return 0; + } /* Sanity check perhaps??? */ if (u.u_dsize > 0x1000000) /* Remember, it's in pages... */ - return 0; + { + bfd_error = wrong_format; + return 0; + } if (u.u_ssize > 0x1000000) - return 0; - /* Check that the size claimed is no greater than the file size. FIXME. */ + { + bfd_error = wrong_format; + return 0; + } + + /* Check that the size claimed is no greater than the file size. */ + { + FILE *stream = bfd_cache_lookup (abfd); + struct stat statbuf; + if (stream == NULL) + return 0; + if (fstat (fileno (stream), &statbuf) < 0) + { + bfd_error = system_call_error; + return 0; + } + if (NBPG * (UPAGES + u.u_dsize + u.u_ssize) > statbuf.st_size) + { + bfd_error = file_truncated; + return 0; + } + if (NBPG * (UPAGES + u.u_dsize + u.u_ssize) < statbuf.st_size) + { + /* The file is too big. Maybe it's not a core file + or we otherwise have bad values for u_dsize and u_ssize). */ + bfd_error = wrong_format; + return 0; + } + } /* OK, we believe you. You're a core file (sure, sure). */ @@ -193,7 +227,11 @@ int trad_unix_core_file_failing_signal (ignore_abfd) bfd *ignore_abfd; { +#ifdef TRAD_UNIX_CORE_FILE_FAILING_SIGNAL + return TRAD_UNIX_CORE_FILE_FAILING_SIGNAL(ignore_abfd); +#else return -1; /* FIXME, where is it? */ +#endif } /* ARGSUSED */ @@ -230,7 +268,7 @@ trad_unix_core_file_matches_executable_p (core_bfd, exec_bfd) #define trad_unix_canonicalize_reloc (unsigned int (*) PARAMS \ ((bfd *, sec_ptr, arelent **, struct symbol_cache_entry**))) bfd_0u #define trad_unix_make_empty_symbol (struct symbol_cache_entry * \ - (*) (bfd *)) bfd_false + (*) PARAMS ((bfd *))) bfd_false #define trad_unix_print_symbol (void (*) PARAMS \ ((bfd *, PTR, struct symbol_cache_entry *, \ bfd_print_symbol_type))) bfd_false @@ -253,6 +291,10 @@ trad_unix_core_file_matches_executable_p (core_bfd, exec_bfd) #define trad_unix_bfd_relax_section bfd_generic_relax_section #define trad_unix_bfd_seclet_link \ ((boolean (*) PARAMS ((bfd *, PTR, boolean))) bfd_false) +#define trad_unix_bfd_reloc_type_lookup \ + ((CONST struct reloc_howto_struct *(*) PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr) +#define trad_unix_bfd_make_debug_symbol \ + ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr) /* If somebody calls any byte-swapping routines, shoot them. */ void @@ -277,15 +319,28 @@ bfd_target trad_core_vec = ' ', /* ar_pad_char */ 16, /* ar_max_namelen */ 3, /* minimum alignment power */ - NO_GET, NO_PUT, NO_GET, NO_PUT, NO_GET, NO_PUT, /* data */ - NO_GET, NO_PUT, NO_GET, NO_PUT, NO_GET, NO_PUT, /* hdrs */ - - {_bfd_dummy_target, _bfd_dummy_target, - _bfd_dummy_target, trad_unix_core_file_p}, - {bfd_false, bfd_false, /* bfd_create_object */ - bfd_false, bfd_false}, - {bfd_false, bfd_false, /* bfd_write_contents */ - bfd_false, bfd_false}, + NO_GET, NO_GET, NO_PUT, /* 64 bit data */ + NO_GET, NO_GET, NO_PUT, /* 32 bit data */ + NO_GET, NO_GET, NO_PUT, /* 16 bit data */ + NO_GET, NO_GET, NO_PUT, /* 64 bit hdrs */ + NO_GET, NO_GET, NO_PUT, /* 32 bit hdrs */ + NO_GET, NO_GET, NO_PUT, /* 16 bit hdrs */ + + { /* bfd_check_format */ + _bfd_dummy_target, /* unknown format */ + _bfd_dummy_target, /* object file */ + _bfd_dummy_target, /* archive */ + trad_unix_core_file_p /* a core file */ + }, + { /* bfd_set_format */ + bfd_false, bfd_false, + bfd_false, bfd_false + }, + { /* bfd_write_contents */ + bfd_false, bfd_false, + bfd_false, bfd_false + }, - JUMP_TABLE(trad_unix) + JUMP_TABLE(trad_unix), + (PTR) 0 /* backend_data */ };