Skip to content

Commit a257a7d

Browse files
committed
Validate a TimeSpec before using it.
Both tv_sec and tv_nsec should be positive and tv_nec < 1000000000. Found by the ZeroPath AI Security Engineer <https://zeropath.com>
1 parent 9139fc5 commit a257a7d

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

logsrvd/logsrvd.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ handle_restart(const RestartMessage *msg, const uint8_t *buf, size_t len,
627627
}
628628

629629
/* Check that message is valid. */
630-
if (msg == NULL || msg->log_id[0] == '\0' || msg->resume_point == NULL) {
630+
if (msg == NULL || msg->log_id[0] == '\0' || !valid_timespec(msg->resume_point)) {
631631
sudo_warnx(U_("%s: %s"), source, U_("invalid RestartMessage"));
632632
closure->errstr = _("invalid RestartMessage");
633633
debug_return_bool(false);
@@ -711,11 +711,12 @@ handle_iobuf(int iofd, const IoBuffer *iobuf, const uint8_t *buf, size_t len,
711711
}
712712

713713
/* Check that message is valid. */
714-
if (iobuf == NULL || iobuf->delay == NULL || iobuf->data.len == 0) {
714+
if (iobuf == NULL || iobuf->data.len == 0 || !valid_timespec(iobuf->delay)) {
715715
sudo_warnx(U_("%s: %s"), source, U_("invalid IoBuffer"));
716716
closure->errstr = _("invalid IoBuffer");
717717
debug_return_bool(false);
718718
}
719+
719720
sudo_debug_printf(SUDO_DEBUG_INFO, "%s: received IoBuffer from %s",
720721
source, __func__);
721722

@@ -758,7 +759,7 @@ handle_winsize(const ChangeWindowSize *msg, const uint8_t *buf, size_t len,
758759
}
759760

760761
/* Check that message is valid. */
761-
if (msg == NULL || msg->delay == NULL) {
762+
if (msg == NULL || !valid_timespec(msg->delay)) {
762763
sudo_warnx(U_("%s: %s"), source, U_("invalid ChangeWindowSize"));
763764
closure->errstr = _("invalid ChangeWindowSize");
764765
debug_return_bool(false);
@@ -794,7 +795,7 @@ handle_suspend(const CommandSuspend *msg, const uint8_t *buf, size_t len,
794795
}
795796

796797
/* Check that message is valid. */
797-
if (msg == NULL || msg->delay == NULL) {
798+
if (msg == NULL || !valid_timespec(msg->delay)) {
798799
sudo_warnx(U_("%s: %s"), source, U_("invalid CommandSuspend"));
799800
closure->errstr = _("invalid CommandSuspend");
800801
debug_return_bool(false);

logsrvd/logsrvd.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
/* Shutdown timeout (in seconds) in case client connections time out. */
4747
#define SHUTDOWN_TIMEO 10
4848

49+
#define valid_timespec(ts) ((ts) != NULL && \
50+
(ts)->tv_sec >= 0 && (ts)->tv_nsec >= 0 && (ts)->tv_nsec < 1000000000)
51+
4952
/*
5053
* Connection status.
5154
* In the RUNNING state we expect I/O log buffers.

0 commit comments

Comments
 (0)