bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug ld/30193] ASCII command length checking corner cases not properly h


From: nickc at redhat dot com
Subject: [Bug ld/30193] ASCII command length checking corner cases not properly handled
Date: Fri, 03 Mar 2023 13:32:08 +0000

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

--- Comment #2 from Nick Clifton <nickc at redhat dot com> ---
Hmmm, I have been thinking about this issue a bit more and uncovered another
problem with the ASCII directive.  It assumes that the space is a constant. 
Consider this:

   % cat ascii.t
   SECTIONS
   {
        .data :
        {
                *(.data)
                data_end = . ;
                ASCII ( 40 - data_end ) "goodbye world"
        }

        /DISCARD/ : { *(*) }
   }

  % ld ../ld/ld-new foo.o -e 0 -T ascii.t

This creates an output file with a gigantic .data section:

  % readelf --wide --sections a.out | grep .data
  [ 1] .data PROGBITS  0000000000000000 001000 2037650 00  WA  0   0  1

because the expression cannot be evaluated at the time that the script is
parsed, so the value field in the etree_type structure is uninitialised.

Fortunately there is an easy fix:

diff --git a/ld/ldgram.y b/ld/ldgram.y
index faffeec94b8..26e56fe1566 100644
--- a/ld/ldgram.y
+++ b/ld/ldgram.y
@@ -672,7 +672,10 @@ statement:
                {
                  /* 'value' is a memory leak, do we care?  */
                  etree_type *value = $3;
-                 lang_add_string (value->value.value, $5);
+                 if (value->type.node_code == INT)
+                   lang_add_string (value->value.value, $5);
+                 else
+                   einfo (_("%X%P:%pS: ASCII expression must be an
integer\n"), NULL);
                }
        | ASCIZ NAME
                {

I am running some regression tests to see if this breaks anything...

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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]