open-eid / libdigidocpp

Libdigidocpp library offers creating, signing and verification of digitally signed documents, according to XAdES and XML-DSIG standards. Documentation http://open-eid.github.io/libdigidocpp
Other
97 stars 45 forks source link

File::fileSize function ignores errors and XmlConf loading is checking incorrectly #598

Closed Muzosh closed 2 months ago

Muzosh commented 2 months ago

Hi, just a small insignificant issue.

XmlConf is checking whether the configuration file size is not 0, otherwise it returns

https://github.com/open-eid/libdigidocpp/blob/41bba271a3f16afacbe35171b7e0546a28c84087/src/XmlConf.cpp#L148-L149

However, the function fileSize itself is typed noexcept and it completely ignores the error_code

https://github.com/open-eid/libdigidocpp/blob/41bba271a3f16afacbe35171b7e0546a28c84087/src/util/File.cpp#L152-L156

If the configuration file does not exist, the error_code is generic:2, but the return value is 18446744073709551615. So the XmlConf continues (because the return value is not equal to 0) even though it shouldn't. It's fine for now, because the next code logic checks whether the file could be parsed into XmlDocument class.

My question is: is this intented? Why would XmlConf just "check whether existing file is empty"? Checking for whether the file exists at all makes more sense, doesn't it?

metsma commented 2 months ago

My bad I missed the error case from documentation.

The non-throwing overload returns static_cast(-1) on errors.

I will prepare PR