1
0
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:
david
2009-02-26 23:47:00 +00:00
parent 200ce037af
commit 940a7fbed4

View File

@@ -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);