2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-08-23 02:17:35 +00:00

Avoid calling fread() with a NUL buffer if msg_len is 0.

Coverity CID 221399
This commit is contained in:
Todd C. Miller 2021-04-23 19:01:44 -06:00
parent d9f0eba1fa
commit 65a55497ec

View File

@ -182,7 +182,8 @@ journal_seek(struct timespec *target, struct connection_closure *closure)
break; break;
} }
/* Read actual message from journal. */ /* Read actual message now that we know the size. */
if (msg_len != 0) {
if (msg_len > bufsize) { if (msg_len > bufsize) {
bufsize = sudo_pow2_roundup(msg_len); bufsize = sudo_pow2_roundup(msg_len);
free(buf); free(buf);
@ -192,7 +193,6 @@ journal_seek(struct timespec *target, struct connection_closure *closure)
} }
} }
/* Read actual message now that we know the size. */
nread = fread(buf, msg_len, 1, closure->journal); nread = fread(buf, msg_len, 1, closure->journal);
if (nread != 1) { if (nread != 1) {
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO, sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
@ -203,6 +203,7 @@ journal_seek(struct timespec *target, struct connection_closure *closure)
closure->errstr = _("error reading journal file"); closure->errstr = _("error reading journal file");
break; break;
} }
}
client_message__free_unpacked(msg, NULL); client_message__free_unpacked(msg, NULL);
msg = client_message__unpack(NULL, msg_len, buf); msg = client_message__unpack(NULL, msg_len, buf);