monitoring-plugins/plugins
Richard Laager 661ecff45c check_ssh: Fix buffer overflow
A buffer overflow was occurring when the server responded with:
Exceeded MaxStartups\r\n

glibc would then abort() with the following output:
*** buffer overflow detected ***: terminated

It was the memset() that was overflowing the buffer.  But the memmove()
needed fixing too.

First off, there was an off-by-one error in both the memmove() and
memset().  byte_offset was already set to the start of the data _past_
the newline (i.e. len + 1).  For the memmove(), incrementing that by 1
again lost the first character of the additional output.  For the
memset(), this causes a buffer overflow.

Second, the memset() has multiple issues.  The comment claims that it
was NULing (sic "null") the "rest".  However, it has no idea how long
the "rest" is, at this point.  It was NULing BUFF_SZ - byte_offset + 1.
After fixing the off-by-one / buffer overflow, it would be NULing
BUFF_SZ - byte_offset.  But that doesn't make any sense.  The length of
the first line has no relation to the length of the second line.

For a quick-and-dirty test, add something like this just inside the
while loop:
memcpy(output,
  "Exceeded MaxStartups\r\nnext blah1 blah2 blah3 blah4\0",
  sizeof("Exceeded MaxStartups\r\nnext blah1 blah2 blah3 blah4\0"));

And, after the memmove(), add:
  printf("output='%s'\n", output);

If you fix the memset() buffer overflow, it will output:
output='ext blah1 blah2 blah3 '

As you can see, the first character is lost.

If you then fix the memmove(), it will output:
output='next blah1 blah2 blah3'

Note that this is still losing the "blah4".

After moving the memset() after byte_offset is set to the new strlen()
of output, then it works correctly:
output='next blah1 blah2 blah3 blah4'

Signed-off-by: Richard Laager <rlaager@wiktel.com>
2025-07-11 18:43:59 -05:00
..
check_apt.d Refactor check_by_ssh 2025-03-10 15:56:34 +01:00
check_by_ssh.d Refactor check_by_ssh 2025-03-10 15:56:34 +01:00
check_cluster.d refactor check_cluster 2025-03-10 22:49:38 +01:00
check_dbi.d Refactor check_dbi 2025-03-07 18:22:42 +01:00
check_dig.d Refactor check_dig 2025-03-10 16:44:17 +01:00
check_disk.d Fixes problems after a4cf2e79f7 2025-03-31 00:46:10 +02:00
check_dns.d Refactor check_dns 2025-03-09 12:04:40 +01:00
check_fping.d check_fping: small style improvement 2025-06-12 11:53:06 +02:00
check_game.d Refactor check_game 2025-03-07 15:58:30 +01:00
check_hpjd.d Refactor check_hpjd 2025-03-11 11:07:26 +01:00
check_ldap.d Remove unintented import 2025-03-11 12:40:32 +01:00
check_load.d check_load some number type fixes 2025-07-06 22:46:41 +02:00
check_mrtg.d Refactor check_mrtg 2025-03-11 12:39:14 +01:00
check_mrtgtraf.d typo: mrtgraf -> mrtgtraf 2025-03-11 16:02:24 +01:00
check_mysql.d Refactor check_mysql 2025-03-11 13:22:13 +01:00
check_mysql_query.d Refactor check_mysql_query 2025-03-11 13:58:56 +01:00
check_nagios.d Refactor check_nagios 2025-03-11 16:18:03 +01:00
check_nt.d Refactor check_nt 2025-03-12 00:36:53 +01:00
check_ntp_peer.d More refactoring 2025-03-12 13:36:04 +01:00
check_ntp_time.d Refactor check_ntp_time 2025-03-12 01:41:48 +01:00
check_pgsql.d Refactor check_pgsql 2025-03-12 02:16:41 +01:00
check_ping.d Refactor check_ping 2025-03-12 13:03:17 +01:00
check_procs.d Fix initialisers for old compilers 2025-03-12 15:50:50 +01:00
check_radius.d Refactor check_radius 2025-03-12 16:51:02 +01:00
check_real.d Refactor check_real 2025-03-12 17:22:17 +01:00
check_smtp.d check_smtp: fix positional host logic 2025-03-10 20:56:09 +01:00
check_ssh.d check_ssh: Move default SSH constant around a bit 2025-03-07 23:38:50 +01:00
check_swap.d check_swap: Fixes on NetBSD 2025-03-17 12:58:12 +01:00
check_tcp.d small fixes to check_tcp config 2025-03-13 13:00:05 +01:00
check_time.d Refactor check_time 2025-03-12 18:14:54 +01:00
check_ups.d Refactor check_ups 2025-03-12 18:40:14 +01:00
negate.d Refactor negate 2025-03-12 21:22:50 +01:00
picohttpparser picohttpparser: clang-format 2024-10-31 14:28:12 +01:00
t check_load: fix tests 2025-07-06 23:16:34 +02:00
tests Address check_disk changes in tests 2025-03-30 22:38:12 +02:00
check_apt.c Refactor check_apt 2025-03-10 10:45:50 +01:00
check_by_ssh.c Refactor check_by_ssh 2025-03-10 15:56:34 +01:00
check_cluster.c refactor check_cluster 2025-03-10 22:49:38 +01:00
check_curl.c check_curl: enable internal cookie handling 2024-12-02 20:48:24 +01:00
check_dbi.c Make config constant 2025-03-07 18:42:37 +01:00
check_dig.c Refactor check_dig 2025-03-10 16:44:17 +01:00
check_disk.c Fixes problems after a4cf2e79f7 2025-03-31 00:46:10 +02:00
check_dns.c ignore CNAMEs in RDNS-mode #1460 2025-03-09 15:43:06 +01:00
check_dummy.c check_dummy: do not export local symbols 2024-10-31 03:36:00 +01:00
check_fping.c Remove options if fping version is too low and die directly 2025-06-12 13:33:50 +02:00
check_game.c check_game: Correct usage to only display the modern option variant 2025-03-07 19:25:14 +01:00
check_hpjd.c Refactor check_hpjd 2025-03-11 11:07:26 +01:00
check_http.c check_http: Adding deprecation text 2025-04-21 10:55:23 +02:00
check_ide_smart.c check_ide_smart: use the more common C90 fixed width integers 2025-03-17 12:56:42 +01:00
check_ldap.c Refactor check_ldap 2025-03-11 12:12:32 +01:00
check_load.c check_load some number type fixes 2025-07-06 22:46:41 +02:00
check_mrtg.c Refactor check_mrtg 2025-03-11 12:39:14 +01:00
check_mrtgtraf.c typo: mrtgraf -> mrtgtraf 2025-03-11 16:02:24 +01:00
check_mysql.c Refactor check_mysql 2025-03-11 13:22:13 +01:00
check_mysql_query.c Refactor check_mysql_query 2025-03-11 13:58:56 +01:00
check_nagios.c Refactor check_nagios 2025-03-11 16:18:03 +01:00
check_nt.c Refactor check_nt 2025-03-12 00:36:53 +01:00
check_ntp.c check_ntp: delare file local variables static 2024-11-08 12:35:27 +01:00
check_ntp_peer.c Fix format specifier 2025-03-12 13:47:13 +01:00
check_ntp_time.c Refactor check_ntp_time 2025-03-12 01:41:48 +01:00
check_pgsql.c Refactor check_pgsql 2025-03-12 02:16:41 +01:00
check_ping.c check_ping: fix some variables forgotten during refactoring 2025-03-17 12:57:21 +01:00
check_procs.c Refactor check_procs 2025-03-12 15:29:36 +01:00
check_radius.c check_radius: allow IPv6 addresses 2025-03-12 16:52:51 +01:00
check_real.c Refactor check_real 2025-03-12 17:22:17 +01:00
check_smtp.c Allow setting of port independent of argument position again 2025-03-10 21:27:50 +01:00
check_snmp.c check_snmp: style + linter fixes 2024-10-31 14:01:12 +01:00
check_ssh.c check_ssh: Fix buffer overflow 2025-07-11 18:43:59 -05:00
check_swap.c check_swap: Fixes on NetBSD 2025-03-17 12:58:12 +01:00
check_tcp.c check_tcp: Actually account for certificate lifetime checks 2025-03-13 14:48:20 +01:00
check_time.c Refactor check_time 2025-03-12 18:14:54 +01:00
check_ups.c Refactor check_ups 2025-03-12 18:40:14 +01:00
check_users.c Revert "Migrate check_users to new ouput infrastructure" 2025-03-07 23:38:50 +01:00
common.h Migrate disk tests from lib, tool 2025-03-18 15:57:44 +01:00
Makefile.am Merge branch 'master' into refactor/check_load 2025-07-06 22:49:04 +02:00
negate.c Reposition include 2025-03-12 21:28:40 +01:00
netutils.c Do not print on failed network connections 2025-03-13 00:43:46 +01:00
netutils.h plugins/netutils: Use C99 booleans 2023-10-18 20:46:16 +02:00
popen.c Implement new output functionality 2025-02-18 21:58:34 +01:00
popen.h Remove check for RETSIGTYPE in autoconf stuff 2023-09-23 12:31:33 +02:00
runcmd.c Implement new output functionality 2025-02-18 21:58:34 +01:00
runcmd.h Project rename initial commit. 2014-01-19 14:18:47 -05:00
sslutils.c change error message for missing certificate 2025-03-17 20:17:28 +01:00
urlize.c urlize: update copyright 2024-10-31 14:48:19 +01:00
utils.c Fix types in perfdata functions 2025-03-07 15:57:46 +01:00
utils.h utils: Make fmt function for compiler 2025-05-18 19:19:23 +02:00