mirror of
https://github.com/neovim/neovim.git
synced 2026-11-02 09:49:02 -06:00
fix(xxd): buffer overread #40236
Problem Buffer overflow if lines exceed the expected buffer size. Solution: Use snprintf instead of strcpy.
This commit is contained in:
1 parent
3d6393540e
commit
966e7a98f5
2 files changed
+9
-1
No files matched your search
+1
-1
@@ -573,7 +573,7 @@ static void xxdline(FILE *fp, char *l, char *colors, int nz)
|
|||||||
static signed char zero_seen = 0;
|
static signed char zero_seen = 0;
|
||||||
|
|
||||||
if (!nz && zero_seen == 1) {
|
if (!nz && zero_seen == 1) {
|
||||||
strcpy(z, l);
|
snprintf(z, sizeof(z), "%s", l);
|
||||||
if (colors) {
|
if (colors) {
|
||||||
memcpy(z_colors, colors, strlen(z));
|
memcpy(z_colors, colors, strlen(z));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ local t = require('test.testutil')
|
|||||||
local n = require('test.functional.testnvim')()
|
local n = require('test.functional.testnvim')()
|
||||||
|
|
||||||
local eq = t.eq
|
local eq = t.eq
|
||||||
|
local eval = n.eval
|
||||||
local clear = n.clear
|
local clear = n.clear
|
||||||
local fn = n.fn
|
local fn = n.fn
|
||||||
local testprg = n.testprg
|
local testprg = n.testprg
|
||||||
@@ -17,4 +18,11 @@ describe('xxd', function()
|
|||||||
local decoded = fn.system({ testprg('xxd'), '-r' }, encoded)
|
local decoded = fn.system({ testprg('xxd'), '-r' }, encoded)
|
||||||
eq(input, decoded)
|
eq(input, decoded)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('handles long lines in revert mode', function()
|
||||||
|
t.skip(t.is_arch('s390x'), 'FIXME: xxd not built correctly on s390x with QEMU?')
|
||||||
|
local long_line = ('4'):rep(512) .. '\n'
|
||||||
|
fn.system({ testprg('xxd'), '-r' }, long_line)
|
||||||
|
eq(0, eval('v:shell_error'))
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
Reference in new issue
Block a user