Skip to content

Commit 06382b8

Browse files
committed
Preserve remaining bytes in the log server read callback functions.
We were not properly handling the case where there were a few bytes left over after processing the message(s). Previously, we would reset the length without moving the remaining bytes to the head of the buffer. This could result in a corrupted message. Thanks to Joshua Rogers for finding this.
1 parent 54bdc7c commit 06382b8

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

logsrvd/logsrvd.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,9 @@ client_msg_cb(int fd, int what, void *v)
11491149
}
11501150
buf->off += msg_len;
11511151
}
1152+
if (buf->len != buf->off) {
1153+
memmove(buf->data, buf->data + buf->off, buf->len - buf->off);
1154+
}
11521155
buf->len -= buf->off;
11531156
buf->off = 0;
11541157

logsrvd/logsrvd_relay.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* SPDX-License-Identifier: ISC
33
*
4-
* Copyright (c) 2019-2022 Todd C. Miller <[email protected]>
4+
* Copyright (c) 2019-2023, 2025 Todd C. Miller <[email protected]>
55
*
66
* Permission to use, copy, modify, and distribute this software for any
77
* purpose with or without fee is hereby granted, provided that the above
@@ -897,6 +897,9 @@ relay_server_msg_cb(int fd, int what, void *v)
897897
goto send_error;
898898
buf->off += msg_len;
899899
}
900+
if (buf->len != buf->off) {
901+
memmove(buf->data, buf->data + buf->off, buf->len - buf->off);
902+
}
900903
buf->len -= buf->off;
901904
buf->off = 0;
902905
debug_return;

logsrvd/sendlog.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* SPDX-License-Identifier: ISC
33
*
4-
* Copyright (c) 2019-2023 Todd C. Miller <[email protected]>
4+
* Copyright (c) 2019-2023, 2025 Todd C. Miller <[email protected]>
55
*
66
* Permission to use, copy, modify, and distribute this software for any
77
* purpose with or without fee is hereby granted, provided that the above
@@ -1428,6 +1428,9 @@ server_msg_cb(int fd, int what, void *v)
14281428
goto bad;
14291429
buf->off += msg_len;
14301430
}
1431+
if (buf->len != buf->off) {
1432+
memmove(buf->data, buf->data + buf->off, buf->len - buf->off);
1433+
}
14311434
buf->len -= buf->off;
14321435
buf->off = 0;
14331436
debug_return;

plugins/sudoers/log_client.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,6 +1856,9 @@ server_msg_cb(int fd, int what, void *v)
18561856
goto bad;
18571857
buf->off += msg_len;
18581858
}
1859+
if (buf->len != buf->off) {
1860+
memmove(buf->data, buf->data + buf->off, buf->len - buf->off);
1861+
}
18591862
buf->len -= buf->off;
18601863
buf->off = 0;
18611864
debug_return;

0 commit comments

Comments
 (0)