aslze / asl

A compact C++ cross-platform library including JSON, XML, HTTP, Sockets, WebSockets, threads, processes, logs, file system, CSV, INI files, vectors and matrices, etc.
Other
68 stars 17 forks source link

A broken ini file causes segfaults when read with write parameter set #15

Closed kabukunz closed 3 years ago

kabukunz commented 3 years ago

Hello, if I create an .ini file like this:

[phase1]
loglevel=1
inputfilename=common/myfile.txt
asasjdh
[phase2]
listno=7
dumbchoices=YES

The string "asasjdh" generates a memory corruption with an unrecoverable segfault out of the .cpp unit which reads it... Reading the file like this:

IniFile config(finalConfigFile, false);

gives no problems whatsoever, but if read with writing option set:

IniFile config(finalConfigFile, true);

the segfault breaks the unit when it returns to the caller. HTH

aslze commented 3 years ago

Hi,

I'll take a look. In the mean time, if you do not write to the file you can pass false as the second argument. The default true means it will save the file on destruction if any item is modified.

aslze commented 3 years ago

Did you use the latest version (master branch or release 1.10.0)?

This commit some time ago fixed an issue that caused a segfault with such a file: https://github.com/aslze/asl/commit/4fecd690ec66aa4aa061c4a0815cbdd8bf8f5f79

OTOH, I saw another related problem that I'll try to solve (if calling explicitly config.write() to write it before destruction).

kabukunz commented 3 years ago

I've tried just now calling write while updating some values. The offending line is deleted; it just disappears. I've not updated to the commit you pointed still; forgot to mention I'm on commit 8cf1a24845e9bc30909bd5917cd5c97ed6f02439 (tag: 1.8.0) HTH

kabukunz commented 3 years ago

Ok I think this is solved, closing it