mirror of
https://github.com/nmap/nmap.git
synced 2025-12-07 13:11:28 +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:
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);
|
||||
|
||||
Reference in New Issue
Block a user