]> git.ipfire.org Git - pakfire.git/commitdiff
cli: table: Check that we have the correct number of columns
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 1 Jul 2025 16:30:35 +0000 (16:30 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 1 Jul 2025 16:30:35 +0000 (16:30 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/cli/lib/table.c

index 366f13c0c248b326085a0c19d17bc08e91c539e6..0521dff6afad1358e48b574263d4cd66123bf34d 100644 (file)
@@ -187,6 +187,7 @@ int cli_table_add_col(cli_table* self, const char* name, cli_table_col_type type
 int cli_table_add_row(cli_table* self, ...) {
        cli_table_col* col = NULL;
        cli_table_row* row = NULL;
+       unsigned int cols = 0;
        char buffer[1024];
        size_t width = 0;
        va_list args;
@@ -237,10 +238,19 @@ int cli_table_add_row(cli_table* self, ...) {
                // Adjust the required width of the column
                if (width > col->width)
                        col->width = width;
+
+               // Count the cols
+               cols++;
        }
 
        va_end(args);
 
+       // Fail if we had an incorrect number of columns
+       if (cols != self->num_cols) {
+               r = -EINVAL;
+               goto ERROR;
+       }
+
        // Append the row
        STAILQ_INSERT_TAIL(&self->rows, row, nodes);