<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 2, 2017 at 1:21 PM, Johan Engelen <span dir="ltr"><<a href="mailto:jbc.engelen@gmail.com" target="_blank">jbc.engelen@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="gmail-">On Wed, Aug 2, 2017 at 9:42 PM, Kostya Serebryany <span dir="ltr"><<a href="mailto:kcc@google.com" target="_blank">kcc@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="gmail-m_3434255852040894958gmail-">On Wed, Aug 2, 2017 at 12:24 PM, Johan Engelen via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi all,<div>  While playing with libFuzzer, it's a little cumbersome to having to copy the buffer just in order to null-terminate it.</div></div></blockquote><div><br></div></span><div>It's just one line, isn't it? </div><div>(Well, in C++; in C this would be 3 lines)</div></div></div></div></blockquote><div><br></div></span><div>One? I know how to in two. Teach me :)  (unfortunately in D, it's 4 lines)</div></div></div></div></blockquote><div><br></div><div>std::string s(reinterpret_cast<const char*>(Data), Size);<br></div><div><br></div><div>Then use s.c_str() instead of Data. </div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="gmail-"><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="gmail-m_3434255852040894958gmail-"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Is a null-terminated buffer an often-enough</div></div></blockquote><div><br></div></span><div>It's somewhat frequent, yes. </div><span class="gmail-m_3434255852040894958gmail-"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div> usage scenario to warrant a libFuzzer commandline configuration switch to always generate a null-terminated test case?</div></div></blockquote><div><br></div></span><div>Such option will need to be *off* by default,</div></div></div></div></blockquote><div><br></div></span><div>definitely</div><span class="gmail-"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> because there are lots of cases where we must not null-terminate the input (otherwise we'll hide some bugs). </div><div>And when an option is off by default and some targets *require* it to be on in order to function properly it becomes a very bad idea, IMHO. </div></div></div></div></blockquote><div><br></div></span><div>That's a good argument. I had not realized that all of the other options aren't requirements (although I've been abusing -only_ascii for that a little bit). Adding `if (data[size-1]) return 0;` to remove the requirement probably doesn't work well with the mutation algorithm.</div></div></div></div></blockquote><div><br></div><div>It may actually work surprisingly well. </div><div>Yes, libFuzzer will spend some extra time creating non-zero terminated mutations, but it won't spend time executing them (due to early exit)</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>I was hoping I could elide the buffer allocation and copy. <br></div></div></div></div></blockquote><div><br></div><div>For performance reasons? </div><div>It makes sense to worry about it only if your target is super-fast (e.g. > 100000 exec/s) and you want to make it even faster. </div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div></div><span class="gmail-"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span style="font-size:12.8px">Besides, the LLVMFuzzerTestOneInput is supposed to be a general interface between the APIs under test and any fuzzing engine (AFL, honggfuzz, SAGE, KLEE, etc) and we should not expect all of them to implement the flag. </span></blockquote><div><br></div></span><div>I was quite surprised not being able to find an option to null terminate :)</div><span class="gmail-HOEnZb"><font color="#888888"><div><br></div><div>-Johan<br></div><div><br></div></font></span></div></div></div>
</blockquote></div><br></div></div>