<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div><span>It would really be better to compare against sizeof(application_id) rather than coupling to all these</span></div><div><span>instances of 4 all over the place.<br></span></div><div><br></div>  <div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"> <div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"> <div dir="ltr"> <font face="Arial" size="2"> <hr size="1">  <b><span style="font-weight:bold;">From:</span></b> Erik de Castro Lopo &lt;mle+la@mega-nerd.com&gt;<br> <b><span style="font-weight: bold;">To:</span></b> flac-dev@xiph.org <br> <b><span style="font-weight: bold;">Sent:</span></b> Thursday, April 5, 2012 4:02:10 AM<br> <b><span style="font-weight: bold;">Subject:</span></b> Re: [flac-dev] [PATCH] Fix buffer overflow in metaflac<br> </font> </div>
 <br>Cristian Rodríguez wrote:<br><br>&gt; strlen() returns the length excluding the terminating null byte..then<br>&gt; an string of len 4 will be off-by-one in application_id[4];<br>&gt; <br>&gt; GCC 4.7 detects this bug.<br><br>Ah nice!<br><br>&gt; diff --git a/src/metaflac/options.c b/src/metaflac/options.c<br>&gt; index eb3498d..2cb0959 100644<br>&gt; --- a/src/metaflac/options.c<br>&gt; +++ b/src/metaflac/options.c<br>&gt; @@ -1040,7 +1040,7 @@ FLAC__bool parse_block_type(const char *in, Argument_BlockType *out)<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; out-&gt;entries[entry].type = FLAC__METADATA_TYPE_APPLICATION;<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; out-&gt;entries[entry].filter_application_by_id = (0 != r);<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(0 != r) {<br>&gt; -&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
 if(strlen(r) == 4) {<br>&gt; +&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(strlen(r) == 3) {<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; strcpy(out-&gt;entries[entry].application_id, r);<br>&gt;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br><br><br>I actually think that this is a better solution:<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(strlen(r) == 4) {<br>-&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  strcpy(out-&gt;entries[entry].application_id, r);<br>+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  memcpy(out-&gt;entries[entry].application_id, r, 4);<br>&nbsp;
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br><br><br>Cheers,<br>Erik<br>-- <br>----------------------------------------------------------------------<br>Erik de Castro Lopo<br><a href="http://www.mega-nerd.com/" target="_blank">http://www.mega-nerd.com/</a><br>_______________________________________________<br>flac-dev mailing list<br><a ymailto="mailto:flac-dev@xiph.org" href="mailto:flac-dev@xiph.org">flac-dev@xiph.org</a><br><a href="http://lists.xiph.org/mailman/listinfo/flac-dev" target="_blank">http://lists.xiph.org/mailman/listinfo/flac-dev</a><br><br><br> </div> </div>  </div></body></html>