Re: [PATCH 12/13] gdb/remote: remove uses of sprintf

Simon Marchi <[email protected]>
Newsgroups gmane.comp.gdb.patches,gmane.comp.gnu.binutils
Message-ID <[email protected]>
On 8/17/26 12:51 PM, Andrew Burgess wrote:
>> @@ -11532,35 +11533,42 @@ remote_add_target_side_condition (struct gdbarch *gdbarch,
>>    /* Send conditions to the target.  */
>>    for (agent_expr *aexpr : bp_tgt->conditions)
>>      {
>> -      xsnprintf (buf, buf_end - buf, "X%x,", (int) aexpr->buf.size ());
>> -      buf += strlen (buf);
>> +      buf += xsnprintf (buf, buf_end - buf, "X%x,", (int) aexpr->buf.size ());
>> +
>>        for (int i = 0; i < aexpr->buf.size (); ++i)
>>  	buf = pack_hex_byte (buf, aexpr->buf[i]);
>> +
> 
> I wonder if we should add an assert here either inside, or just after,
> the loop, to check that we've not blown past BUF_END?  Unless I'm
> misunderstanding this, these PACK_HEX_BYTE calls could overrun the
> buffer, right?

I noted in the commit message that I didn't do it, because I wanted to
focus just on the *printf calls, but I can always do it as a follow-up.

Simon
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.