Skip to content

Commit

Permalink
hexdump: fix NUL character handling
Browse files Browse the repository at this point in the history
When dumping a file containing some NUL characters, the display is wrong
because all remaining characters on the line are replaced by NUL. This
error comes from the fact that the copy of the read buffer into the
line buffer is done using strncpy() which handles NUL character as end
of string and pads the destination buffer with NUL afterwards.

To avoid data manipulation during buffer copy, simply replace strncpy()
with its memory equivalent memcpy() that does not interpret the read
data.

Signed-off-by: Mathieu Anquetin <mathieu.anquetin@groupe-cahors.com>
  • Loading branch information
man-gc authored and landley committed Mar 14, 2024
1 parent ea11915 commit cab0b66
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion toys/pending/hexdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void do_hexdump(int fd, char *name)
continue;

newline:
strncpy(TT.linebuf+(TT.bc%16), toybuf, TT.len);
memcpy(TT.linebuf+(TT.bc%16), toybuf, TT.len);
TT.bc = TT.bc % 16 + TT.len;
sl = 0;
if (TT.pos + TT.bc == TT.s+TT.n || TT.fn == toys.optc || TT.bc == 16) {
Expand Down

0 comments on commit cab0b66

Please sign in to comment.