mirror of
https://github.com/sudo-project/sudo.git
synced 2025-08-22 09:57:41 +00:00
Avoid calling fread() with a NUL buffer if msg_len is 0.
Coverity CID 221399
This commit is contained in:
parent
d9f0eba1fa
commit
65a55497ec
@ -182,28 +182,29 @@ 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 > bufsize) {
|
if (msg_len != 0) {
|
||||||
bufsize = sudo_pow2_roundup(msg_len);
|
if (msg_len > bufsize) {
|
||||||
free(buf);
|
bufsize = sudo_pow2_roundup(msg_len);
|
||||||
if ((buf = malloc(bufsize)) == NULL) {
|
free(buf);
|
||||||
closure->errstr = _("unable to allocate memory");
|
if ((buf = malloc(bufsize)) == NULL) {
|
||||||
|
closure->errstr = _("unable to allocate memory");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nread = fread(buf, msg_len, 1, closure->journal);
|
||||||
|
if (nread != 1) {
|
||||||
|
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
|
||||||
|
"unable to read message from %s", closure->journal_path);
|
||||||
|
if (feof(closure->journal))
|
||||||
|
closure->errstr = _("unexpected EOF reading journal file");
|
||||||
|
else
|
||||||
|
closure->errstr = _("error reading journal file");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read actual message now that we know the size. */
|
|
||||||
nread = fread(buf, msg_len, 1, closure->journal);
|
|
||||||
if (nread != 1) {
|
|
||||||
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
|
|
||||||
"unable to read message from %s", closure->journal_path);
|
|
||||||
if (feof(closure->journal))
|
|
||||||
closure->errstr = _("unexpected EOF reading journal file");
|
|
||||||
else
|
|
||||||
closure->errstr = _("error reading journal file");
|
|
||||||
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);
|
||||||
if (msg == NULL) {
|
if (msg == NULL) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user