Page MenuHome GnuPG

argparse.c (optfile_parse): Off-by-one-error without a trailing newline.
Closed, WontfixPublic

Description

If gpg.conf contains an invalid option on the last line, but there is no trailing newline, the wrong line number for this invalid option is reported.

Example:

echo -n "wrong_option" > ~/.gnupg/gpg.conf
gpg --list-conf

Result:

gpg: gpg.conf:0:invalid option

Expected:

gpg: gpg.conf:1:invalid option

Possible fix: (not tested for side-effects)

--- a/common/argparse.c
+++ b/common/argparse.c
@@ -599,8 +599,7 @@ optfile_parse (FILE *fp, const char *filename, unsigned *lineno,
         c = getc (fp);
       if (c == '\n' || c== EOF )
         {
-          if ( c != EOF )
-            ++*lineno;
+          ++*lineno;
           if (state == -1)
             break;
           else if (state == 2)

Details

Version
2.1.21

Event Timeline

werner claimed this task.
werner added a subscriber: werner.

That is a matter of taste. A line requires a LF - many tools even ignore the last line or print a warning for a missing final LF. Not having a final LF is a bad idea.

Thanks for reporting but I have a different taste ;-)