>Synopsis: The ordering of the iked flags -d and -n erroneously changes
>the debug level.
>Category: bin
>Description:
I've found an issue with iked's command line flag processing where the
order of
the -d and -n flags affects the resulting debug level. This appears to
be a bug
since flag ordering shouldn't change the program's behavior.
Problem:
- `iked -d -n` results in debug level 1
- `iked -n -d` results in debug level 2
The issue occurs because the -n flag unconditionally sets debug=1
rather than
preserving any existing debug level:
```c
case 'd':
debug++;
break;
case 'n':
debug = 1; /* Overwrites any previous debug
setting */
opts |= IKED_OPT_NOACTION;
break;
```
Impact:
This can lead to unexpected behavior where debug messages may or may
not appear
depending solely on flag order. Users expecting to see debug output
when using
both flags may not see it if they happen to put the flags in the wrong
order.
>How-To-Repeat:
1. Run: iked -d -n -v -v
2. Note debug level and visible output
3. Run: iked -n -d -v -v
4. Note debug level and visible output
5. Observe that debug levels differ between the two commands
>Fix:
Make -n preserve existing debug level:
```c
case 'n':
if (!debug) debug = 1; /* Only set if not already set */
opts |= IKED_OPT_NOACTION;
break;
```