[PATCH] libelf: Fix possible memory leak in elf_getdata_rawchunk

2023-11-08 Thread Mark Wielaard
If the rawchunk is not properly aligned we'll create a new buffer
that is correctly aligned and put the data in that new buffer with
memcpy or the conversion function. In such cases the rawchunk leaks
because the new buffer is put into the Elf_Data_Chunk.

* libelf/elf_getdata_rawchunk.c (elf_getdata_rawchunk):
Call free on the rawchunk if new buffer was allocated.

Signed-off-by: Mark Wielaard 
---
 libelf/elf_getdata_rawchunk.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/libelf/elf_getdata_rawchunk.c b/libelf/elf_getdata_rawchunk.c
index 05ff329c..1751878d 100644
--- a/libelf/elf_getdata_rawchunk.c
+++ b/libelf/elf_getdata_rawchunk.c
@@ -175,6 +175,8 @@ elf_getdata_rawchunk (Elf *elf, int64_t offset, size_t 
size, Elf_Type type)
 
  /* The copy will be appropriately aligned for direct access.  */
  memcpy (buffer, rawchunk, size);
+
+ free (rawchunk);
}
 }
   else
@@ -191,6 +193,9 @@ elf_getdata_rawchunk (Elf *elf, int64_t offset, size_t 
size, Elf_Type type)
 
   /* Call the conversion function.  */
   (*__elf_xfctstom[elf->class - 1][type])(buffer, rawchunk, size, 0);
+
+  if (!flags)
+   free (rawchunk);
 }
 
   /* Allocate the dummy container to point at this buffer.  */
-- 
2.41.0



[PATCH] elfutils: PR 30991 srcfiles tarball feature

2023-11-08 Thread Housam Alamour
* srclines.cxx: Introduce new option that places all the
source files associated with a specified dwarf/elf file
into a zip file and sends it to stdout.

* run-srcfiles-self.sh: Added test-case for the new zip feature.

* srcfiles.1, NEWS: Added documentation for the new zip feature

Example:
% ./src/srcfiles -z -e /bin/ls > output.zip

https://sourceware.org/bugzilla/show_bug.cgi?id=30991

Signed-off-by: Housam Alamour 
---
 NEWS   |   4 +
 configure.ac   |  15 +++
 doc/srcfiles.1 |  20 +++-
 src/Makefile.am|   2 +-
 src/srcfiles.cxx   | 193 ++---
 tests/run-srcfiles-self.sh |  40 +++-
 6 files changed, 251 insertions(+), 23 deletions(-)

diff --git a/NEWS b/NEWS
index 53c717eb..388a3b63 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,9 @@
 Version 0.190
 
+srcfiles: added srcfiles tool that lists all the source files of a given 
+  DWARF/ELF file. May also be used to create fetch the source files and
+  place them into a zip.
+
 readelf: Support readelf -Ds, --use-dynamic --symbol.
 
 debuginfod: Schema change (reindexing required, sorry!) for a 60%
diff --git a/configure.ac b/configure.ac
index 29ed32fe..3bfd2097 100644
--- a/configure.ac
+++ b/configure.ac
@@ -880,6 +880,21 @@ AC_ARG_ENABLE(debuginfod-urls,
 AC_SUBST(DEBUGINFOD_URLS, $default_debuginfod_urls)
 AC_CONFIG_FILES([config/profile.sh config/profile.csh])
 
+dnl Check if libarchive is available to determine if the
+dnl srcfiles --zip option should be enabled or disabled
+AC_CACHE_CHECK([whether libarchive is available],
+ac_cv_have_libarchive,
+[AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
+#include 
+]])],
+ac_cv_have_libarchive=yes,
+ac_cv_have_libarchive=no)])
+AS_IF([test "x$ac_cv_have_libarchive" = "xyes"],
+[
+AC_DEFINE([HAVE_LIBARCHIVE], [1], [Define to 1 if libarchive is 
available])
+])
+AM_CONDITIONAL([HAVE_LIBARCHIVE], [test "x$ac_cv_have_libarchive" = "xyes"])
+
 AC_OUTPUT
 
 AC_MSG_NOTICE([
diff --git a/doc/srcfiles.1 b/doc/srcfiles.1
index 6149c21b..6157045b 100644
--- a/doc/srcfiles.1
+++ b/doc/srcfiles.1
@@ -21,15 +21,18 @@
 eu-srcfiles \- Lists the source files of a DWARF/ELF file.
 
 .SH "SYNOPSIS"
-eu-srcfiles [\fB\-0\fR|\fB\-\-null\fR] [\fB\-c\fR|\fB\-\-cu\-only\fR] 
[\fB\-v\fR|\fB\-\-verbose\fR] INPUT
+eu-srcfiles [\fB\-0\fR|\fB\-\-null\fR] [\fB\-c\fR|\fB\-\-cu\-only\fR] 
[\fB\-v\fR|\fB\-\-verbose\fR] [\fB\-z\fR|\fB\-\-zip\fR] INPUT
 
 .SH "DESCRIPTION"
-\fBeu-srcfiles\fR lists the source files of a given \s-DWARF/ELF\s0
+\fBeu-srcfiles\fR lists all the source files of a given DWARF/ELF
 file.  This list is based on a search of the DWARF debuginfo, which
 may be automatically fetched by debuginfod if applicable.  The target
 file may be an executable, a coredump, a process, or even the running
 kernel.  The default is the file 'a.out'.  The source file names are
-made unique and printed to standard output.
+made unique and printed to standard output. The source files can be
+placed in a zip file that is sent to stdout.
+
+Note that all occurrences of '/./' and '/../' in the path name are 
canonicalized.
 
 .SH "INPUT OPTIONS"
 The long and short forms of options, shown here as alternatives, are
@@ -78,7 +81,7 @@ Print program version.
 
 .TP
 \fB\-0, \-\-null\fR
-Separate items by a null instead of a newline.
+Separate items by a null instead of a newline. Cannot be used with the zip 
option becuase it raises errors when unzipping.
 
 .TP
 \fB\-c, \-\-cu\-only\fR
@@ -88,6 +91,10 @@ Only list the CU names.
 \fB\-v, \-\-verbose\fR
 Increase verbosity of logging messages.
 
+.TP
+\fB\-z, \-\-zip\fR
+Zip all the source files and send to stdout. Cannot be used with the null 
option becuase it raises errors when unzipping.
+
 
 .SH EXAMPLES
 
@@ -119,6 +126,11 @@ List the source files of a kernel image.
 eu-srcfiles -e /boot/vmlinuz-`uname -r`
 .ESAMPLE
 
+Zip all the source files for a binary.
+.SAMPLE
+eu-srcfiles -z -e /bin/ls > ls.zip
+.ESAMPLE
+
 
 .SH "AUTHOR"
 Written by Housam Alamour.
diff --git a/src/Makefile.am b/src/Makefile.am
index d3d9d408..3853c152 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -85,7 +85,7 @@ stack_LDADD = $(libebl) $(libelf) $(libdw) $(libeu) 
$(argp_LDADD) $(demanglelib)
 elfcompress_LDADD = $(libebl) $(libelf) $(libdw) $(libeu) $(argp_LDADD)
 elfclassify_LDADD = $(libelf) $(libdw) $(libeu) $(argp_LDADD)
 srcfiles_SOURCES = srcfiles.cxx
-srcfiles_LDADD = $(libdw) $(libelf) $(libeu)  $(argp_LDADD)
+srcfiles_LDADD = $(libdw) $(libelf) $(libeu)  $(argp_LDADD) $(libarchive_LIBS)
 
 installcheck-binPROGRAMS: $(bin_PROGRAMS)
bad=0; pid=; list="$(bin_PROGRAMS)"; for p in $$list; do \
diff --git a/src/srcfiles.cxx b/src/srcfiles.cxx
index 3c7afdc4..b88ce919 100644
--- a/src/srcfiles.cxx
+++ b/src/srcfiles.cxx
@@ -15,7 +15,19 @@
 
You should have received a copy of the GNU General Public License
along with this

[Bug general/31027] Remove asserts from library code

2023-11-08 Thread dichen at redhat dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=31027

Di Chen  changed:

   What|Removed |Added

   Assignee|unassigned at sourceware dot org   |dichen at redhat dot com

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Re: [PATCH v2 0/5] Add support for MIPS

2023-11-08 Thread Ying Huang
Hi,

在 2023/11/3 19:56, Mark Wielaard 写道:
> Hi Yimg,
>
> On Thu, 2023-11-02 at 14:55 +0800, Ying Huang wrote:
>> This is a series of modifications about MIPS.
>> Support src/readelf, strip, elflint, objdump related tools.
> Thanks. What are the changes compared to v1?
> https://patchwork.sourceware.org/project/elfutils/list/?series=18813
>
>> Pass all previous test cases that failed due to MIPS non-support.
>> The following are the test results on mips64el.
>> # TOTAL: 271
>> # PASS:  263
>> # SKIP:  8
>> # XFAIL: 0
>> # FAIL:  0
>> # XPASS: 0
>> # ERROR: 0
> That looks pretty good. What distro/gcc/glibc/kernel was this against?
>
> Cheers,
>
> Mark

Debian GNU/Linux 11

gcc version 12.2.0

glibc  2.36-9

kernel version 5.10.0-22-loongson-3


Thanks,

Ying