cmdmon: initialize all bytes of reply buffer
Instead of zeroing individual fields, zero all bytes of the buffer before the reply is formed. This may have a small impact on performance, but it simplifies the code and minimizes the risk of leaking uninitialized memory.
This commit is contained in:
parent
58c2915878
commit
499a69e611
1 changed files with 2 additions and 13 deletions
15
cmdmon.c
15
cmdmon.c
|
@ -1069,9 +1069,6 @@ handle_client_accesses_by_index(CMD_Request *rx_message, CMD_Reply *tx_message)
|
||||||
tx_message->reply = htons(RPY_CLIENT_ACCESSES_BY_INDEX2);
|
tx_message->reply = htons(RPY_CLIENT_ACCESSES_BY_INDEX2);
|
||||||
tx_message->data.client_accesses_by_index.n_indices = htonl(n_indices);
|
tx_message->data.client_accesses_by_index.n_indices = htonl(n_indices);
|
||||||
|
|
||||||
memset(tx_message->data.client_accesses_by_index.clients, 0,
|
|
||||||
sizeof (tx_message->data.client_accesses_by_index.clients));
|
|
||||||
|
|
||||||
for (i = req_first_index, j = 0; i < (uint32_t)n_indices && j < req_n_clients; i++) {
|
for (i = req_first_index, j = 0; i < (uint32_t)n_indices && j < req_n_clients; i++) {
|
||||||
if (!CLG_GetClientAccessReportByIndex(i, &report, &now))
|
if (!CLG_GetClientAccessReportByIndex(i, &report, &now))
|
||||||
continue;
|
continue;
|
||||||
|
@ -1109,9 +1106,6 @@ handle_manual_list(CMD_Request *rx_message, CMD_Reply *tx_message)
|
||||||
MNL_ReportSamples(report, MAX_MANUAL_LIST_SAMPLES, &n_samples);
|
MNL_ReportSamples(report, MAX_MANUAL_LIST_SAMPLES, &n_samples);
|
||||||
tx_message->data.manual_list.n_samples = htonl(n_samples);
|
tx_message->data.manual_list.n_samples = htonl(n_samples);
|
||||||
|
|
||||||
memset(tx_message->data.manual_list.samples, 0,
|
|
||||||
sizeof (tx_message->data.manual_list.samples));
|
|
||||||
|
|
||||||
for (i=0; i<n_samples; i++) {
|
for (i=0; i<n_samples; i++) {
|
||||||
sample = &tx_message->data.manual_list.samples[i];
|
sample = &tx_message->data.manual_list.samples[i];
|
||||||
UTI_TimespecHostToNetwork(&report[i].when, &sample->when);
|
UTI_TimespecHostToNetwork(&report[i].when, &sample->when);
|
||||||
|
@ -1343,19 +1337,14 @@ read_from_cmd_socket(int sock_fd, int event, void *anything)
|
||||||
expected_length = PKL_CommandLength(&rx_message);
|
expected_length = PKL_CommandLength(&rx_message);
|
||||||
rx_command = ntohs(rx_message.command);
|
rx_command = ntohs(rx_message.command);
|
||||||
|
|
||||||
|
memset(&tx_message, 0, sizeof (tx_message));
|
||||||
|
|
||||||
tx_message.version = PROTO_VERSION_NUMBER;
|
tx_message.version = PROTO_VERSION_NUMBER;
|
||||||
tx_message.pkt_type = PKT_TYPE_CMD_REPLY;
|
tx_message.pkt_type = PKT_TYPE_CMD_REPLY;
|
||||||
tx_message.res1 = 0;
|
|
||||||
tx_message.res2 = 0;
|
|
||||||
tx_message.command = rx_message.command;
|
tx_message.command = rx_message.command;
|
||||||
tx_message.reply = htons(RPY_NULL);
|
tx_message.reply = htons(RPY_NULL);
|
||||||
tx_message.status = htons(STT_SUCCESS);
|
tx_message.status = htons(STT_SUCCESS);
|
||||||
tx_message.pad1 = 0;
|
|
||||||
tx_message.pad2 = 0;
|
|
||||||
tx_message.pad3 = 0;
|
|
||||||
tx_message.sequence = rx_message.sequence;
|
tx_message.sequence = rx_message.sequence;
|
||||||
tx_message.pad4 = 0;
|
|
||||||
tx_message.pad5 = 0;
|
|
||||||
|
|
||||||
if (rx_message.version != PROTO_VERSION_NUMBER) {
|
if (rx_message.version != PROTO_VERSION_NUMBER) {
|
||||||
DEBUG_LOG("Command packet has invalid version (%d != %d)",
|
DEBUG_LOG("Command packet has invalid version (%d != %d)",
|
||||||
|
|
Loading…
Reference in a new issue