get_lastlog2() copies the TTY and host strings read from the lastlog2
database into heap buffers of sizeof(ut_line)+1 and sizeof(ut_host)+1
bytes, but passed strlen(value)+1 as the mem2strcpy() limit. mem2strcpy()
zero-fills and copies that many bytes regardless of the destination, so a
database value longer than the field overflows the buffer. Cap the limit
to the destination field size, matching the wtmp and plain-lastlog paths
in the same function.
Signed-off-by: aizu-m <aizumusheer2@gmail.com>
return -1;
}
if (res_tty) {
- mem2strcpy(dst, res_tty, strlen(res_tty), strlen(res_tty) + 1);
+ mem2strcpy(dst, res_tty, strlen(res_tty),
+ sizeof_member(struct utmpx, ut_line) + 1);
free (res_tty);
}
break;
return -1;
}
if (res_host) {
- mem2strcpy(dst, res_host, strlen(res_host), strlen(res_host) + 1);
+ mem2strcpy(dst, res_host, strlen(res_host),
+ sizeof_member(struct utmpx, ut_host) + 1);
free(res_host);
}
break;