Opened 5 years ago

Last modified 5 years ago

#13125 new Bugs

parse_config_file silently ignores IO errors

Reported by: Johannes Spangenberg <johannes.spangenberg@…> Owned by: Vladimir Prus
Milestone: To Be Determined Component: program_options
Version: Boost Release Branch Severity: Problem
Keywords: Cc:

Description

The function parse_config_file silently ignores I/O errors while reading the configuration file.

A easy way to reproduce the bug is to specify a directory as configuration file. On Linux, open will succeed but subsequent calls to read will fail with EISDIR.

---

Minimal and complete program to reproduce the problem:

#include <cerrno>
#include <iostream>

#include <boost/program_options.hpp>

using namespace boost::program_options;


int main(int argc, char *argv[])
{
    if (argc != 2) {
        std::cerr << "Invalid amount of arguments" << std::endl;
        return 1;
    }

    try {
        options_description desc("Desc");
        variables_map vm;
        store(parse_config_file<char>(argv[1], desc), vm);
        notify(vm);
    } catch (error &e) {
        std::cerr << "Error: " << e.what() << std::endl;
        return 1;
    }
    std::cerr << "Everything fine" << std::endl;
    return 0;
}
$ ./a.out some-non-existent-file
Error: can not read options configuration file 'some-non-existent-file'
$ ./a.out .
Everything fine

Change History (1)

comment:1 by Johannes Spangenberg <johannes.spangenberg@…>, 5 years ago

Since I was not able to attach a patch to this issue (Trac error: "IndexError: pop from empty list"), I created a pull request on GitHub.

https://github.com/boostorg/program_options/pull/29

Note: See TracTickets for help on using tickets.