>Synopsis:      fdformat(1) doesn't return documented values on error
>Category:      user
        If you look at the current src/usr.sbin/fdformat/fdformat.{1,c} 
        files (.1 rev 1.21 and .c rev 1.25), the man page says:
        "an exit status of 2 reflects invalid arguments given to the 
        program"

        However, if you look at the option parsing in the getopt() loop 
        inside fdformat.c (such as at line 177), the program can return 
        1 if the arguments are invalid. There is also some option 
        parsing outside the getopt() loop that returns 1 on error at 
        lines 265 and 273.

        Additionally, the program returns 2 if malloc() fails which is 
        fine, but it should be documented in the man page that 2 is the 
        return value if "an error occurs," that is, any error other than 
        one related to formatting the fd, not limited to invalid 
        arguments. The error return on malloc() failure also makes the 
        minor stylistic mistake of calling fprintf():
                fprintf (stderr, "\nfdformat: out of memory\n");
        It should be err():
                err(1, "malloc");

>How-To-Repeat:
        The following command will show one of the cases where the 
        program returns 1 when the man page says it should return 2:
        $ fdformat -c NaN

>Fix:
        Just make it return 2 where appropriate. I would send such a 
        simple fix myself, but I was waiting for someone to reply to or 
        commit https://marc.info/?l=openbsd-tech&m=170183956928304&w=2 
        because a diff which fixes this bug would cause a conflict with 
        that diff, but there hasn't been a reply or commit after a few 
        months.

Reply via email to