Commit Graph

49 Commits

Author SHA1 Message Date
David Anderson
1304f68c0b On Msys2 (Windows) these have to have O_BINARY
set for open().  was left off of these two before.
	modified:   fuzz/fuzz_die_cu.c
	modified:   fuzz/fuzz_die_cu_e.c
2025-08-25 10:52:59 -07:00
David Anderson
581fc7f17d Two places failed to spell DWREGRESSIONTEMP
correctly in #ifdef
	modified:   fuzz/fuzz_aranges.c
	modified:   fuzz/fuzz_crc_32.c
2025-08-21 15:09:22 -07:00
David Anderson
550d3570b2 When LIBDWARFTEMP is defined change the name
of the temp file to start with junk
to better match what is routine in the regressiontests.
And to something that works just fine with Win msys2.
(in msys2 "/tmp/anything" will not work for open(  "wb")
whereas "anything" will work.)
        modified:   fuzz/fuzz_aranges.c
	modified:   fuzz/fuzz_crc.c
	modified:   fuzz/fuzz_crc_32.c
	modified:   fuzz/fuzz_debug_addr_access.c
	modified:   fuzz/fuzz_debug_str.c
	modified:   fuzz/fuzz_debuglink.c
	modified:   fuzz/fuzz_die_cu.c
	modified:   fuzz/fuzz_die_cu_attrs.c
	modified:   fuzz/fuzz_die_cu_attrs_loclist.c
	modified:   fuzz/fuzz_die_cu_e.c
	modified:   fuzz/fuzz_die_cu_e_print.c
	modified:   fuzz/fuzz_die_cu_info1.c
	modified:   fuzz/fuzz_die_cu_offset.c
	modified:   fuzz/fuzz_die_cu_print.c
	modified:   fuzz/fuzz_dnames.c
	modified:   fuzz/fuzz_findfuncbypc.c
	modified:   fuzz/fuzz_gdbindex.c
	modified:   fuzz/fuzz_globals.c
	modified:   fuzz/fuzz_gnu_index.c
	modified:   fuzz/fuzz_init_b.c
	modified:   fuzz/fuzz_init_binary.c
	modified:   fuzz/fuzz_init_path.c
	modified:   fuzz/fuzz_macro_dwarf4.c
	modified:   fuzz/fuzz_macro_dwarf5.c
	modified:   fuzz/fuzz_rng.c
	modified:   fuzz/fuzz_set_frame_all.c
	modified:   fuzz/fuzz_showsectgrp.c
	modified:   fuzz/fuzz_simplereader_tu.c
	modified:   fuzz/fuzz_srcfiles.c
	modified:   fuzz/fuzz_stack_frame_access.c
	modified:   fuzz/fuzz_str_offsets.c
	modified:   fuzz/fuzz_tie.c
	modified:   fuzz/fuzz_xuindex.c
	modified:   src/lib/libdwarf/libdwarf.h
2025-08-20 14:40:18 -07:00
David Anderson
3651896470 First use of this testcase today.
The testcase emitted one printf string
which had no ending newline.
That provoked a warning from diff
which looked ugly.
So I added a terminating newline to the one and only printf
in the code.
	modified:   fuzz/fuzz_aranges.c
2024-12-10 10:39:28 -08:00
David Anderson
e69eb5da56 The test code fuzz/fuzz_die_cu_attrs.c fails to test library
return codes in a loop and runs an unreasonably long time.
It's not an infinite loop, but memory is accumulating
pretty fast.
Results in megabytes of useless error messages from libdwarf.
I have changed the test source to check for a null 'attr'
and stop the loop right away. With a short message.

This is DW2024-002  oss fuzz id 371659894

	modified:   fuzz/fuzz_die_cu_attrs.c
2024-12-09 14:06:46 -08:00
Jeremy Rifkin
62838e8663 Remove trailing whitespace from files (#229)
* Remove trailing whitespace from files

* Remove whitespace from pdfbuild.sh

---------

Co-authored-by: David Anderson <dandelot@linuxmail.org>
2024-02-29 08:54:35 -08:00
David Anderson
321b001e93 - Dwarf_Off dw_offset;
+    /* libdwarf does not require offset to be anything in
+       particular, and will work fine regardless
+       (possibly returning DW_DLV_ERROR or DW_DLV_OK).  But
+       valgrind generates a warning passing in the uninitialized
+       value so let us initialize it to ... something. */
+    Dwarf_Off dw_offset = 11;
	modified:   fuzz/fuzz_debug_str.c

    Additional doc on dwarf_get_str() for completeness.
	modified:   src/lib/libdwarf/libdwarf.h
2024-02-06 16:06:29 -08:00
David Anderson
182e935240 Fixed so no longer forcing read of
uninitialized memory.
valgrind noticed the bug.
	modified:   fuzz/fuzz_crc.c

Added comments.
	modified:   fuzz/fuzz_crc_32.c
2024-01-31 11:43:20 -08:00
David Anderson
d76cce559b With latest info on debuglink issues
modified:   bugxml/data.txt
The source here uses a libdwarf public
function incorrectly which
guarantees a memory leak. Now the test case
follows the rules...
	modified:   fuzz/fuzz_debuglink.c

Fix so that dwarf_gnu_debuglink() will not
dereference a NULL pointer.
	modified:   src/lib/libdwarf/dwarf_debuglink.c

Clarify the doxgen comments on dwarf_gnu_debuglink().
	modified:   src/lib/libdwarf/libdwarf.h
2023-11-25 15:00:23 -08:00
David Anderson
b2d1f44e6a Missing the #define of O_BINARY. Fixed now.
modified:   fuzz/fuzz_debuglink.c
2023-11-24 10:38:13 -08:00
David Anderson
4e585d13d5 Adding space characers in | to force rebuild.
modified:   fuzz/fuzz_crc.c
2023-11-18 08:04:08 -08:00
David Anderson
be0a501c95 Added two new fuzz files as examples of using
dwarf_next_cu_header_e() and dwarf_siblingof_c()
	modified:   fuzz/Makefile.am
2023-11-16 10:59:46 -08:00
David Anderson
5ea9cce104 These are using the new dwarf_next_cu_header_e()
new file:   fuzz_die_cu_e.c
	new file:   fuzz_die_cu_e_print.c
2023-11-13 14:32:13 -08:00
David Anderson
e9355ca7a3 Accidentally omitted an ifndef on O_BINARY. Fixed.
modified:   fuzz_crc.c
2023-11-06 10:05:29 -08:00
David Anderson
3df08b8af7 These were not treating O_BINARY correctly and/or
failing to use it at all. It is necessary on Windows
to read object files properly.
No change in logic at all.
	modified:   fuzz/fuzz_aranges.c
	modified:   fuzz/fuzz_crc.c
	modified:   fuzz/fuzz_crc_32.c
	modified:   fuzz/fuzz_debug_addr_access.c
	modified:   fuzz/fuzz_debug_str.c
	modified:   fuzz/fuzz_debuglink.c
	modified:   fuzz/fuzz_die_cu.c
	modified:   fuzz/fuzz_die_cu_attrs.c
	modified:   fuzz/fuzz_die_cu_attrs_loclist.c
	modified:   fuzz/fuzz_die_cu_info1.c
	modified:   fuzz/fuzz_die_cu_offset.c
	modified:   fuzz/fuzz_die_cu_print.c
	modified:   fuzz/fuzz_dnames.c
	modified:   fuzz/fuzz_gdbindex.c
	modified:   fuzz/fuzz_globals.c
	modified:   fuzz/fuzz_gnu_index.c
	modified:   fuzz/fuzz_init_b.c
	modified:   fuzz/fuzz_init_binary.c
	modified:   fuzz/fuzz_macro_dwarf4.c
	modified:   fuzz/fuzz_macro_dwarf5.c
	modified:   fuzz/fuzz_rng.c
	modified:   fuzz/fuzz_set_frame_all.c
	modified:   fuzz/fuzz_showsectgrp.c
	modified:   fuzz/fuzz_simplereader_tu.c
	modified:   fuzz/fuzz_srcfiles.c
	modified:   fuzz/fuzz_stack_frame_access.c
	modified:   fuzz/fuzz_str_offsets.c
	modified:   fuzz/fuzz_tie.c
	modified:   fuzz/fuzz_xuindex.c

Fixing the reporting of filenames so that even on msys2
the report is sensible (for msys2)
	modified:   src/bin/dwarfdump/dwarfdump.c

Tweak to make it work.
	modified:   src/lib/libdwarf/meson.build

Introducing the correct header ifdefs involving DWP_API
to match the concept in libdwarf.h
	modified:   src/lib/libdwarfp/libdwarfp.h
2023-11-02 13:15:44 -07:00
David Anderson
e00930a692 Now we test O_BINARY and only if not already set set it to zero.
Because in the msys2 windows environment O_BINARY has a value already
(from system headers). So we avoid a poinless warning.
	modified:   fuzz/fuzz_aranges.c
	modified:   fuzz/fuzz_debug_str.c
	modified:   fuzz/fuzz_dnames.c
	modified:   fuzz/fuzz_gdbindex.c
	modified:   fuzz/fuzz_globals.c
	modified:   fuzz/fuzz_gnu_index.c
	modified:   fuzz/fuzz_init_b.c
	modified:   fuzz/fuzz_macro_dwarf4.c
	modified:   fuzz/fuzz_set_frame_all.c
	modified:   fuzz/fuzz_str_offsets.c
2023-10-31 12:40:33 -07:00
David Anderson
c95f058487 Added clarifying comments about printing
macro data and handling of macro import.
No logic change.
	modified:   doc/checkexamples.c
	modified:   fuzz/fuzz_macro_dwarf5.c
	modified:   src/bin/dwarfdump/print_macro.c
2023-07-08 12:22:31 -07:00
David Anderson
e8c726e2be Adding printing of DW_CFA_LLVM_def_aspace_cfa_sf
address space
	modified:   fuzz/fuzz_set_frame_all.c

DW202306-004
fuzzer: ossfuzz id: 59595
	modified:   src/lib/libdwarf/dwarf_frame.c
2023-06-10 10:50:18 -07:00
David Anderson
2e23d54423 Modified indent on one line.
modified:   fuzz/fuzz_set_frame_all.c
2023-06-08 18:14:58 -07:00
David Anderson
cf16fa633b A printf was lacking a newline, making the
output very odd-looking for no good reason.
Added a newline to the printf.
	modified:   fuzz/fuzz_set_frame_all.c
2023-06-04 09:11:17 -07:00
David Anderson
12a612fc8d DW202305-009 ossfuzz id: 56451
Changed by adding initializers of zero
to local variables not previously initialized.
	modified:   fuzz/fuzz_dnames.c

Added checks to dwarf_dnames_abbrevtable()
so required pointers are verified non-null before use.
Still never returns DW_DLV_ERROR. With required
input pointers missing it returns DW_DLV_NO_ENTRY.
	modified:   src/lib/libdwarf/dwarf_debugnames.c
2023-05-30 12:52:02 -07:00
David Anderson
21b33d1302 It was calling exit() early, not allowing
dwarf_finish() to be called.  ossfuzz 56462

And it was doing a local malloc and
failing to call free() on that local space
in some situations.
ossfuzz 58026

	modified:   fuzz/fuzz_set_frame_all.c
2023-05-30 08:55:06 -07:00
David Anderson
8b17d41a31 Document DW202305-006 ossfuzz id: 56472
The test code as written here
gets an error from valgrind for calling libdwarf
with an uninitialized pointer.  The fix is to
initialize the Dwarf_Die instance by adding  = 0;
This was not a libdwarf bug (the original
fix actually fixed a libdwarf bug, and this
valgrind issue pointed out the need for the test case fix..
	modified:   bugxml/data.txt
	modified:   fuzz/fuzz_simplereader_tu.c
2023-05-30 08:00:10 -07:00
David Anderson
5612eff9f1 DW202305-005 ossfuzz id: 56462
To avoid leaks the libdwarf calling program
MUST call dwarf_finish(). The code here
was failing to do that in a number of
error situations.
Now it just returns from functions on error
and lets main() call dwarf_finish(),
a call that has always been in main().
	modified:   fuzz/fuzz_set_frame_all.c
2023-05-30 07:47:52 -07:00
David Anderson
e2ef955656 Amplified comment.
modified:   fuzz/fuzz_crc_32.c
2023-05-29 20:50:00 -07:00
David Anderson
abaec0a1bb Adding a comment instead of actually fixing the source.
modified:   fuzz/fuzz_crc_32.c
2023-05-23 17:56:59 -07:00
David Anderson
97a7812226 Repairing the examplep5() function which
specified an infinite loop.
The doc/checkexamples.c examplep5() code
was hard to understand.
	modified:   fuzz/fuzz_macro_dwarf5.c
2023-05-23 15:30:06 -07:00
David Anderson
c6e4f105ec A printf in the test code was missing its
ending newline. That lead to annoying messages
when doing a diff of the program text output..
Now the printf has its newline.
	modified:   fuzz/fuzz_set_frame_all.c
2023-05-23 14:02:00 -07:00
David Anderson
448b8fb4f6 This is test code, not part of libdwarf.
An uninitialized local variable named 'die'
would crash the caller when passed to any
libdwarf function.
C code cannot check random pointers for
validity.
Fixed by initializing the variable to 0.
	modified:   fuzz/fuzz_die_cu_attrs_loclist.c
2023-05-23 13:20:31 -07:00
David Anderson
6fac1021c6 oss fuzz 56446 DW202305-004
An local pointer initialized with
just 'stack trash'  (so no proper
initializer) was passed to
libdwarf. That is a mistake in the test code.
C cannot determine if a non-null value is a legitimate
value as a pointer.
Not a library bug.
	modified:   fuzz/fuzz_dnames.c
2023-05-23 10:32:29 -07:00
David Anderson
2783706a87 Adding memset to initialize a local struct instance
to avoid unpredictable behavior while running.
valgrind complained about it.
	modified:   fuzz_findfuncbypc.c
2023-05-19 15:27:39 -07:00
David Anderson
1c8ad2fbbc Added a comment documenting that the code
can leak memory as in case of certain
errors found in corrupt dwarf it immiately
exit()s and does not call dwarf_finish().
Arranged that in case of some errors the
code prints the error name, not the error
number.
	modified:   fuzz/fuzz_set_frame_all.c
2023-04-15 11:09:44 -07:00
David Anderson
5ac919ea71 Many local variables were used that had
no initializer. function exampled().
While that may not have changed the output
it is extremely bad proctice.
And can easily lead to irreproducible results.
Now all initialized to zero. No other change.
	modified:   fuzz/fuzz_srcfiles.c
2023-04-06 16:05:24 -07:00
David Anderson
f8032529c9 All these had free(errp) which
here is harmless as errp is null,
but whether a Dwarf_Error * is
null or not free() on it is never
appropriate, and if not-null
the free is very wrong.

	modified:   fuzz_die_cu_offset.c
	modified:   fuzz_die_cu_print.c
	modified:   fuzz_showsectgrp.c
2023-03-28 14:52:23 -07:00
David Anderson
2b19bc239f Fixing a mistake in this test source,
which was doing a free() that is
documented as inappropriate..
	modified:   fuzz/fuzz_die_cu_attrs.c
2023-03-28 11:06:23 -07:00
David Anderson
51617feed2 The fuzz/* files have to be in a distribution
for testing to fully work. So now they are.
	modified:   Makefile.am
	modified:   configure.ac
	new file:   fuzz/Makefile.am
	new file:   fuzz/README.md
2023-03-27 15:49:07 -07:00
David Anderson
0d02f95164 The declaration/definition
Dwarf_Die die;
was both uninitialized and unused.
Removed it.
	modified:   fuzz/fuzz_die_cu.c
2023-03-26 16:48:42 -07:00
David Anderson
e4053c9a0f Fixes oss fuzz 57335. The test case is
kind of pushing the bounds here.
	modified:   bugxml/data.txt

oss fuzz  57335.
Added a comment, the call will fail as written.
But now there will be no library crash.
	modified:   fuzz/fuzz_die_cu_attrs.c

Added a new error,  DW_DLE_INVALID_NULL_ARGUMENT(498)
	modified:   src/lib/libdwarf/dwarf_errmsg_list.h

    Now returns DW_DLV_ERROR
    if dw_return_bool is passed in as NULL.
	modified:   src/lib/libdwarf/dwarf_form.c

Added a new error,  DW_DLE_INVALID_NULL_ARGUMENT(498)
Documented the dw_return_bool pointer
to dwarf_hasform() more completely.
	modified:   src/lib/libdwarf/libdwarf.h
2023-03-24 15:57:00 -07:00
David Anderson
266e832df8 free(errp) is always wrong, removed it.
Ensured on return from the LLVM fuzz interface
always dwarf_finish() close() and unlink
	modified:   fuzz/fuzz_die_cu_attrs_loclist.c
2023-03-22 14:50:46 -07:00
David Anderson
ade1be5d2e Every return from the *LLVM* function has to
do certain hosekeeping
to avoid leaks (dwarf_finish(dhg) for example).
Several here failed to do that.
	modified:   fuzz/fuzz_rng.c
2023-03-22 06:07:20 -07:00
David Anderson
cc6e97128f These has local Dwarf_Die pointers
left uninitialized. That violates
the requirements of the libdwarf API.
Now set to 0 at declaration.
	modified:   fuzz/fuzz_die_cu_attrs.c
	modified:   fuzz/fuzz_die_cu_offset.c
2023-03-21 10:51:01 -07:00
David Anderson
1ff4365bd6 Removed all instances of free(errp)
where errp is
   Dwarf_Error *errp
as that is never necessary or appropriate.
Any leftover allocations made in libdwarf
and not 'dwarf_dealloc*' or documented
as user-must-free data returned via pointers
to the caller are
automatically freed by dwarf_finish()
unless there are libdwarf bugs.
	modified:   fuzz_die_cu.c
	modified:   fuzz_die_cu_attrs.c
	modified:   fuzz_die_cu_info1.c
	modified:   fuzz_die_cu_offset.c
	modified:   fuzz_die_cu_print.c
	modified:   fuzz_macro_dwarf5.c
	modified:   fuzz_showsectgrp.c
	modified:   fuzz_simplereader_tu.c
	modified:   fuzz_srcfiles.c
	modified:   fuzz_stack_frame_access.c
	modified:   fuzz_xuindex.c
2023-03-20 11:20:33 -07:00
David Anderson
16a4078e91 Before dereferenceing errp ensure errp
is not NULL.
	modified:   fuzz_debug_addr_access.c
	modified:   fuzz_findfuncbypc.c
	modified:   fuzz_set_frame_all.c
2023-03-20 11:15:38 -07:00
David Anderson
2eced75af9 All instances of
Dwarf_Error error;
changed to
Dwarf_Error error = 0;
to avoid unwanted stack random bytes in the pointer.
	modified:   fuzz/fuzz_aranges.c
	modified:   fuzz/fuzz_crc_32.c
	modified:   fuzz/fuzz_debug_str.c
	modified:   fuzz/fuzz_die_cu.c
	modified:   fuzz/fuzz_die_cu_attrs.c
	modified:   fuzz/fuzz_die_cu_attrs_loclist.c
	modified:   fuzz/fuzz_die_cu_info1.c
	modified:   fuzz/fuzz_die_cu_offset.c
	modified:   fuzz/fuzz_die_cu_print.c
	modified:   fuzz/fuzz_dnames.c
	modified:   fuzz/fuzz_findfuncbypc.c
	modified:   fuzz/fuzz_gdbindex.c
	modified:   fuzz/fuzz_globals.c
	modified:   fuzz/fuzz_gnu_index.c
	modified:   fuzz/fuzz_init_b.c
	modified:   fuzz/fuzz_macro_dwarf4.c
	modified:   fuzz/fuzz_macro_dwarf5.c
	modified:   fuzz/fuzz_set_frame_all.c
	modified:   fuzz/fuzz_simplereader_tu.c
	modified:   fuzz/fuzz_srcfiles.c
	modified:   fuzz/fuzz_stack_frame_access.c
	modified:   fuzz/fuzz_str_offsets.c
	modified:   fuzz/fuzz_xuindex.c
	modified:   src/lib/libdwarf/dwarf_rnglists.c
2023-03-20 11:07:41 -07:00
David Anderson
c04edfaf20 new file: fuzz_debug_addr_access.c 2023-03-20 10:58:54 -07:00
David Anderson
b55ce01855 Merge branch 'master' of https://github.com/davea42/libdwarf-code
Due to fuzz issues.
2023-03-07 08:40:03 -08:00
David Anderson
48bbdb9d9f Fixes here for several fuzzing issues. WIll show numbers
shortly.
	modified:   bugxml/dwarfbug.html
	modified:   bugxml/dwarfbuglohi.html
	modified:   src/bin/dwarfdump/print_debug_gnu.c
	modified:   src/lib/libdwarf/dwarf_gnu_index.c
	modified:   src/lib/libdwarf/dwarf_gnu_index.h
	modified:   src/lib/libdwarf/libdwarf.h
2023-03-07 08:38:31 -08:00
madamantis-leviathan
d9c14b2b12 Remove functions that are no longer available from the source (#154) 2023-03-07 08:03:27 -08:00
David Anderson
9cab819ba3 Source used for testing/fuzzing.
new file:   fuzz/fuzz_aranges.c
	new file:   fuzz/fuzz_crc.c
	new file:   fuzz/fuzz_crc_32.c
	new file:   fuzz/fuzz_debug_addr_access.c
	new file:   fuzz/fuzz_debug_str.c
	new file:   fuzz/fuzz_debuglink.c
	new file:   fuzz/fuzz_die_cu.c
	new file:   fuzz/fuzz_die_cu_attrs.c
	new file:   fuzz/fuzz_die_cu_attrs_loclist.c
	new file:   fuzz/fuzz_die_cu_info1.c
	new file:   fuzz/fuzz_die_cu_offset.c
	new file:   fuzz/fuzz_die_cu_print.c
	new file:   fuzz/fuzz_dnames.c
	new file:   fuzz/fuzz_findfuncbypc.c
	new file:   fuzz/fuzz_gdbindex.c
	new file:   fuzz/fuzz_globals.c
	new file:   fuzz/fuzz_gnu_index.c
	new file:   fuzz/fuzz_init_b.c
	new file:   fuzz/fuzz_init_binary.c
	new file:   fuzz/fuzz_init_path.c
	new file:   fuzz/fuzz_macro_dwarf4.c
	new file:   fuzz/fuzz_macro_dwarf5.c
	new file:   fuzz/fuzz_rng.c
	new file:   fuzz/fuzz_set_frame_all.c
	new file:   fuzz/fuzz_showsectgrp.c
	new file:   fuzz/fuzz_simplereader_tu.c
	new file:   fuzz/fuzz_srcfiles.c
	new file:   fuzz/fuzz_stack_frame_access.c
	new file:   fuzz/fuzz_str_offsets.c
	new file:   fuzz/fuzz_tie.c
	new file:   fuzz/fuzz_xuindex.c
2023-02-18 08:52:54 -08:00