mirror of
https://github.com/sudo-project/sudo.git
synced 2025-08-22 01:49:11 +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;
|
||||
}
|
||||
|
||||
/* Read actual message from journal. */
|
||||
if (msg_len > bufsize) {
|
||||
bufsize = sudo_pow2_roundup(msg_len);
|
||||
free(buf);
|
||||
if ((buf = malloc(bufsize)) == NULL) {
|
||||
closure->errstr = _("unable to allocate memory");
|
||||
/* Read actual message now that we know the size. */
|
||||
if (msg_len != 0) {
|
||||
if (msg_len > bufsize) {
|
||||
bufsize = sudo_pow2_roundup(msg_len);
|
||||
free(buf);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/* 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);
|
||||
msg = client_message__unpack(NULL, msg_len, buf);
|
||||
if (msg == NULL) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user