https://sourceware.org/bugzilla/show_bug.cgi?id=30193
Bug ID: 30193 Summary: ASCII command length checking corner cases not properly handled Product: binutils Version: 2.41 (HEAD) Status: UNCONFIRMED Severity: normal Priority: P2 Component: ld Assignee: unassigned at sourceware dot org Reporter: pexu at sourceware dot mail.kapsi.fi Target Milestone: --- Created attachment 14727 --> https://sourceware.org/bugzilla/attachment.cgi?id=14727&action=edit Handle ASCII corner cases, adjust test case accordingly Hi. ASCII (expr) "string" length checking is currently off by one and zero length is handled in a manner that might be unexpected. ld/ldlang.c: (excerpt, in-between lines omitted) 8464 if (size == 0) 8466 size = len + 1; 8467 else if (len >= size) 8468 { 8469 len = size - 1; 8473 } `size' is the output size (zero for ASCIZ), and `len' is the actual length of the input string (that has been processed). As the checking currently uses `len >= size' it is not possible to output a string that is exactly the allocated size, e.g. `ASCII (5) "ascii"'. Also, as lang_add_string() processes both ASCIZ and ASCII commands it is not possible to produce an empty output, e.g. `ASCII (0) ""'. This might be useful if the command would be used to produce variable padding. Attaching a proposed patch that solves both of these issues. Instead of relying on `size == 0' a simple boolean is added (think this as optional< size_t >). Also, updated the test case to handle these corner cases, including one that leads to input string truncation. (Also, now there are no trailing whitespaces in the expected result.) -- You are receiving this mail because: You are on the CC list for the bug.