]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add command to explicitly clear the data buffer
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 19 Oct 2019 15:20:19 +0000 (11:20 -0400)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 19 Oct 2019 15:20:24 +0000 (11:20 -0400)
This can be useful when tracking down non-deterministic issues

src/bin/unit_test_attribute.c

index ecadc32a49dbb5bcaf58566ab7840f9aa6b46fa2..92fe4ffe7d24a549053b470be81409ed776cb9bc 100644 (file)
@@ -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 <attr> = <value>",
                                        .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 <string>",
@@ -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, "<INVALID>"), data_used);
        } else {
                DEBUG2("%s[%d]: --> %s", cc->filename, cc->lineno,