Skip to content

Commit

Permalink
Revert "Use memcpy instead of strncpy"
Browse files Browse the repository at this point in the history
This reverts commit 9294cbf.

memcpy can lead to a buffer overflow if name is shorter than 8 bytes. The
compiler warning aside, strncpy seems like exactly the right tool for the job
as we want at most 8 bytes and don't care for any trailing \0, but are OK with
zero padding at the end.
  • Loading branch information
niner committed Jan 8, 2021
1 parent 85de985 commit 3171bdb
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/profiler/heapsnapshot.c
Expand Up @@ -890,8 +890,8 @@ void serialize_attribute_stream(MVMThreadContext *tc, MVMHeapSnapshotCollection
}

{
char namebuf[8] = {0};
memcpy(namebuf, name, 8);
char namebuf[8];
strncpy(namebuf, name, 8);
fwrite(namebuf, 8, 1, fh);
}

Expand Down

0 comments on commit 3171bdb

Please sign in to comment.