fix some bounds checks

This commit is contained in:
Addison Crump
2024-02-02 11:43:11 +01:00
parent e07a0a005d
commit 35972c6a3d
2 changed files with 24 additions and 14 deletions

View File

@@ -61,25 +61,31 @@ handle_parent_connection (int s)
"Parent (%d) received command %lu from client.",
getpid (), cmnd->command);
if (cmnd->data_size >= BUFSIZ) {
syslog_message (LOG_WARNING,
"Client sent %lu bytes, but buffer is %lu",
cmnd->data_size, (unsigned long)BUFSIZ);
return;
}
memset (resp, 0, sizeof (glibtop_response));
memset (parameter, 0, sizeof (parameter));
if (cmnd->data_size) {
if (cmnd->data_size >= BUFSIZ) {
syslog_message (LOG_WARNING,
"Client sent %lu bytes, but buffer is %lu",
cmnd->data_size, (unsigned long)BUFSIZ);
return;
}
if (enable_debug)
syslog_message (LOG_DEBUG, "Client has %lu bytes of data.",
cmnd->data_size);
do_read (s, parameter, cmnd->data_size);
} else if (cmnd->size) {
if (cmnd->size >= BUFSIZ) {
syslog_message (LOG_WARNING,
"Client sent %lu bytes, but buffer is %lu",
cmnd->size, (unsigned long)BUFSIZ);
return;
}
memcpy (parameter, cmnd->parameter, cmnd->size);
}

View File

@@ -44,22 +44,26 @@ handle_slave_connection (int input, int output)
glibtop_debug ("Slave %d received command "
"%lu from client.", getpid (), cmnd->command);
if (cmnd->data_size >= BUFSIZ)
glibtop_error ("Client sent %lu bytes, "
"but buffer is %lu",
cmnd->size, (unsigned long)BUFSIZ);
memset (resp, 0, sizeof (glibtop_response));
memset (parameter, 0, sizeof (parameter));
if (cmnd->data_size) {
if (cmnd->data_size >= BUFSIZ)
glibtop_error ("Client sent %lu bytes, "
"but buffer is %lu",
cmnd->data_size, (unsigned long)BUFSIZ);
glibtop_debug ("Client has %lu bytes of data.",
cmnd->data_size);
do_read (input, parameter, cmnd->data_size);
} else if (cmnd->size) {
if (cmnd->size >= BUFSIZ)
glibtop_error ("Client sent %lu bytes, "
"but buffer is %lu",
cmnd->size, (unsigned long)BUFSIZ);
memcpy (parameter, cmnd->parameter, cmnd->size);
}