<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Suspicious use of sizeof(pointer) in FuzzerMutate.cpp"
   href="https://bugs.llvm.org/show_bug.cgi?id=36148">36148</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Suspicious use of sizeof(pointer) in FuzzerMutate.cpp
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>5.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>wolf@behrenhoff.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>In file lib/Fuzzer/FuzzerMutate.cpp, the function RandCh (lines 63--67) looks
like this:


static char RandCh(Random &Rand) {
  if (Rand.RandBool()) return Rand(256);
  const char *Special = "!*'();:@&=+$,/?%#[]012Az-`~.\xff\x00";
  return Special[Rand(sizeof(Special) - 1)];
}

Special is thus a pointer to char. In the return line sizeof(pointer)-1 is used
as index. I think the intention was to return any of the predefined characters,
not any of the first 4-1=3 or 8-1=7 characters (or whatever size a pointer is
on the target platform).

I suggest using an array instead of a pointer:

  const char Special[] = "!*'();:@&=+$,/?%#[]012Az-`~.\xff\x00";


I haven't tested this, but surely the sizeof(pointer) is wrong :-)

This bug is at least present in the 5.0.1 download. If it is also in 6 or
trunk: I don't know. Please check!

Cheers!</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>