]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
client/lldpcli: guard argc>0 before indexing argv
authorVincent Bernat <vincent@bernat.ch>
Sat, 9 May 2026 12:56:05 +0000 (14:56 +0200)
committerVincent Bernat <vincent@bernat.ch>
Sat, 9 May 2026 13:26:12 +0000 (15:26 +0200)
When the input is comment-only (e.g. "# foo"), tokenize_line() returns
zero tokens; `argv[argc - 1]` then reads `argv[-1]`. Guard the access.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
src/client/lldpcli.c

index 4286e02429f5f005f4c1be4e148378e7f07c2b0f..2c4d39617cbfd1180a32bc9118afe8d308c48d03 100644 (file)
@@ -216,7 +216,7 @@ _cmd_complete(int all)
 
        char *compl =
            commands_complete(root, argc, (const char **)argv, all, is_privileged());
-       if (compl &&strlen(argv[argc - 1]) < strlen(compl )) {
+       if (compl &&argc > 0 && strlen(argv[argc - 1]) < strlen(compl )) {
                if (rl_insert_text(compl +strlen(argv[argc - 1])) < 0) {
                        free(compl );
                        goto end;