occtl: Fix missing column headers in 'show ip bans' output

Existing code used the loop index 'i == 0' to determine when to print
column headers. However, a 'continue' statement inside the loop could
skip the 'i = 0' iteration, causing the headers to never be printed.

Introduced a separate boolean 'header_printed' variable to track
whether headers have been printed.

Closes: #677

Signed-off-by: Grigory Trenin <grigory.trenin@gmail.com>
This commit is contained in:
Grigory Trenin
2025-12-14 14:38:42 -05:00
committed by Nikos Mavrogiannopoulos
parent 3892e032d9
commit 1c31314df4
2 changed files with 7 additions and 2 deletions

1
NEWS
View File

@@ -8,6 +8,7 @@
- Fixed 'iroute' option processing to handle multiple routes (#625)
- occtl: fix invalid JSON output in `occtl -j show iroutes` (#661)
- occtl: fix regression with trailing commas in `occtl -j show sessions` (#669)
- occtl: fix missing column headers in 'show ip bans' output (#677)
- Fixed DTLS not working with systemd socket activation (#647)
* Version 1.3.0 (released 2024-05-05)

View File

@@ -21,6 +21,7 @@
*/
#include <config.h>
#include <stdbool.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
@@ -1077,6 +1078,7 @@ static int handle_list_banned_cmd(struct unix_ctx *ctx, const char *arg,
FILE *out;
struct tm *tm, _tm;
time_t t;
bool header_printed = false;
PROTOBUF_ALLOCATOR(pa, ctx);
char txt_ip[MAX_IP_STR];
@@ -1123,9 +1125,10 @@ static int handle_list_banned_cmd(struct unix_ctx *ctx, const char *arg,
continue;
}
if (i == 0 && NO_JSON(params)) {
if (!header_printed && NO_JSON(params)) {
fprintf(out, "%14s %14s %30s\n", "IP", "score",
"expires");
header_printed = true;
}
print_start_block(out, params);
@@ -1144,8 +1147,9 @@ static int handle_list_banned_cmd(struct unix_ctx *ctx, const char *arg,
str_since, tmpbuf);
}
} else {
if (i == 0 && NO_JSON(params)) {
if (!header_printed && NO_JSON(params)) {
fprintf(out, "%14s %14s\n", "IP", "score");
header_printed = true;
}
print_start_block(out, params);