From: Arran Cudbard-Bell Date: Sat, 19 Oct 2019 15:20:19 +0000 (-0400) Subject: Add command to explicitly clear the data buffer X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cd7f26644c60c3fb546557f1e59da9cd26155ff1;p=thirdparty%2Ffreeradius-server.git Add command to explicitly clear the data buffer This can be useful when tracking down non-deterministic issues --- diff --git a/src/bin/unit_test_attribute.c b/src/bin/unit_test_attribute.c index ecadc32a49d..92fe4ffe7d2 100644 --- a/src/bin/unit_test_attribute.c +++ b/src/bin/unit_test_attribute.c @@ -890,6 +890,16 @@ static size_t command_normalise_attribute(command_result_t *result, command_ctx_ RETURN_OK(len); } +/* + * Clear the data buffer + */ +static size_t command_clear(command_result_t *result, UNUSED command_ctx_t *cc, + char *data, size_t UNUSED data_used, UNUSED char *in, UNUSED size_t inlen) +{ + memset(data, 0, COMMAND_OUTPUT_MAX); + RETURN_NOOP(0); +} + /* * Add a command by talloc'ing a table for it. */ @@ -1672,6 +1682,11 @@ static fr_table_ptr_sorted_t commands[] = { .usage = "attribute = ", .description = "Parse and reprint an attribute value pair, writing \"ok\" to the data buffer on success" }}, + { "clear", &(command_entry_t){ + .func = command_clear, + .usage = "clear", + .description = "Explicitly zero out the contents of the data buffer" + }}, { "command add ", &(command_entry_t){ .func = command_radmin_add, .usage = "command add ", @@ -1849,7 +1864,7 @@ size_t process_line(command_result_t *result, command_ctx_t *cc, char *data, siz data[data_used] = '\0'; /* Ensure the data buffer is \0 terminated */ if (data_used) { - DEBUG2("%s[%d]: --> %s (wrote %zu bytes)", cc->filename, cc->lineno, + DEBUG2("%s[%d]: --> %s (%zu bytes in buffer)", cc->filename, cc->lineno, fr_table_str_by_value(command_rcode_table, result->rcode, ""), data_used); } else { DEBUG2("%s[%d]: --> %s", cc->filename, cc->lineno,