提交 ae3f88f6 编写于 作者: L Laszlo Ersek 提交者: Luiz Capitulino

dump: fill in the flat header signature more pleasingly to the eye

The "mh.signature" array field has size 16, and is zeroed by the preceding
memset(). MAKEDUMPFILE_SIGNATURE expands to a string literal with string
length 12 (size 13). There's no need to measure the length of
MAKEDUMPFILE_SIGNATURE at runtime, nor for the extra zero-filling of
"mh.signature" with strncpy().

Use memcpy() with MIN(sizeof, sizeof) for robustness (which is an integer
constant expression, evaluable at compile time.)
Approximately-suggested-by: NPaolo Bonzini <pbonzini@redhat.com>
Signed-off-by: NLaszlo Ersek <lersek@redhat.com>
Reviewed-by: NPaolo Bonzini <pbonzini@redhat.com>
Signed-off-by: NLuiz Capitulino <lcapitulino@redhat.com>
上级 b780bf8e
......@@ -716,8 +716,8 @@ static int write_start_flat_header(int fd)
int ret = 0;
memset(&mh, 0, sizeof(mh));
strncpy(mh.signature, MAKEDUMPFILE_SIGNATURE,
strlen(MAKEDUMPFILE_SIGNATURE));
memcpy(mh.signature, MAKEDUMPFILE_SIGNATURE,
MIN(sizeof mh.signature, sizeof MAKEDUMPFILE_SIGNATURE));
mh.type = cpu_to_be64(TYPE_FLAT_HEADER);
mh.version = cpu_to_be64(VERSION_FLAT_HEADER);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册