global/global_context: always add '\0' after strncpy()

see also f35fa1c58cf24275458cb83097c57bdfd1184cf8

Signed-off-by: Kefu Chai <kchai@redhat.com>
This commit is contained in:
Kefu Chai 2019-05-31 22:34:28 +08:00
parent 880468b4bf
commit 8ceb11416d

View File

@ -57,10 +57,12 @@ int note_io_error_event(
{
g_eio = true;
if (devname) {
strncpy(g_eio_devname, devname, sizeof(g_eio_devname));
strncpy(g_eio_devname, devname, sizeof(g_eio_devname) - 1);
g_eio_devname[sizeof(g_eio_devname) - 1] = '\0';
}
if (path) {
strncpy(g_eio_path, path, sizeof(g_eio_path));
strncpy(g_eio_path, path, sizeof(g_eio_path) - 1);
g_eio_path[sizeof(g_eio_path) - 1] = '\0';
}
g_eio_error = error;
g_eio_iotype = iotype;