[4/6] src: Prevent invalid include of binary into compilation

Message ID 20241010102559.9162-5-mcpratt@pm.me
State Dropped
Headers
Series Various portability fixes and organization |

Commit Message

Michael Pratt Oct. 10, 2024, 10:27 a.m. UTC
  The "stack" binary built by elfutils has the same name
as the standard C++ header <stack>.

If that header were to be in the list of includes
while building the C++ elfutils program "srcfiles",
then there is a chance that the "stack" binary
is included instead and treated as text,
leading to a decode error
if "stack" happens to be built first
and "." is in the include paths.

Adding the result of C++ compilation srcfiles.o
to the dependencies of "stack" ensures that
the C++ compilation will happen first,
before the stack binary is present.

While this doesn't guarantee an error will not occur
in all cases, it does guarantee that it will not occur
from a clean build state.

      * src/Makefile.am: Add compilation dependency between
      the stack and srcfiles binaries.

Signed-off-by: Michael Pratt <mcpratt@pm.me>
---
 src/Makefile.am | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Aaron Merey Oct. 11, 2024, 7:09 p.m. UTC | #1
Hi Michael,

On Thu, Oct 10, 2024 at 6:27 AM Michael Pratt <mcpratt@pm.me> wrote:
>
> The "stack" binary built by elfutils has the same name
> as the standard C++ header <stack>.
>
> If that header were to be in the list of includes
> while building the C++ elfutils program "srcfiles",
> then there is a chance that the "stack" binary
> is included instead and treated as text,
> leading to a decode error
> if "stack" happens to be built first
> and "." is in the include paths.
>
> Adding the result of C++ compilation srcfiles.o
> to the dependencies of "stack" ensures that
> the C++ compilation will happen first,
> before the stack binary is present.
>
> While this doesn't guarantee an error will not occur
> in all cases, it does guarantee that it will not occur
> from a clean build state.

I believe this issue was recently fixed in commit b426c4db31e7.

Aaron
  
Michael Pratt Oct. 12, 2024, 4:33 a.m. UTC | #2
Hi, thanks for the reply,

On Friday, October 11th, 2024 at 15:09, Aaron Merey <amerey@redhat.com> wrote:

> 
> I believe this issue was recently fixed in commit b426c4db31e7.


Yeah, this looks like it handles the problem more directly,
thanks for pointing it out.

However, it would be nice if DEFAULT_INCLUDES was AC_SUBST'd
instead of just blank for this case.

Do you need me to resend the series without this patch?

--
MCP
  

Patch

diff --git a/src/Makefile.am b/src/Makefile.am
index e0267d96..c5474c68 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -94,6 +94,7 @@  strings_LDADD = $(libelf) $(libeu) $(argp_LDADD)
 ar_LDADD = libar.a $(libelf) $(libeu) $(argp_LDADD) $(obstack_LIBS)
 unstrip_LDADD = $(libebl) $(libelf) $(libdw) $(libeu) $(argp_LDADD)
 stack_LDADD = $(libebl) $(libelf) $(libdw) $(libeu) $(argp_LDADD) $(demanglelib)
+EXTRA_stack_DEPENDENCIES = $(if $(findstring srcfiles,$(bin_PROGRAMS)),$(srcfiles_OBJECTS))
 elfcompress_LDADD = $(libebl) $(libelf) $(libdw) $(libeu) $(argp_LDADD)
 elfclassify_LDADD = $(libelf) $(libdw) $(libeu) $(argp_LDADD)
 srcfiles_SOURCES = srcfiles.cxx