mirror of
https://github.com/nmap/nmap.git
synced 2026-05-13 16:57:06 +00:00
In genfry (general array-scrambling function), don't swap an array element with
itself. memcpy is undefined when the source and destination overlap. Thanks to Brandon for uncovering this.
This commit is contained in:
parent
200ce037af
commit
940a7fbed4
1 changed files with 5 additions and 3 deletions
8
utils.cc
8
utils.cc
|
|
@ -317,9 +317,11 @@ iptr = (unsigned int *) bytes;
|
|||
pos = *iptr; iptr++;
|
||||
}
|
||||
pos %= i+1;
|
||||
memcpy(tmp, arr + elem_sz * i, elem_sz);
|
||||
memcpy(arr + elem_sz * i, arr + elem_sz * pos, elem_sz);
|
||||
memcpy(arr + elem_sz * pos, tmp, elem_sz);
|
||||
if ((unsigned) i != pos) { /* memcpy is undefined when source and dest overlap. */
|
||||
memcpy(tmp, arr + elem_sz * i, elem_sz);
|
||||
memcpy(arr + elem_sz * i, arr + elem_sz * pos, elem_sz);
|
||||
memcpy(arr + elem_sz * pos, tmp, elem_sz);
|
||||
}
|
||||
}
|
||||
free(bytes);
|
||||
free(tmp);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue