Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault in aug_save if file not writeable #178

Closed
stromnet opened this issue Nov 21, 2014 · 3 comments
Closed

Segmentation fault in aug_save if file not writeable #178

stromnet opened this issue Nov 21, 2014 · 3 comments
Labels

Comments

@stromnet
Copy link

Hi,
I noticed that aug_save will segfault if the target file is not writeable.

FreeBSD 10.0
augeas 1.2.0 (1.3.0 tested too, same issue)

Minimal test case:

#include <fcntl.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <augeas.h>
int main(int argc, char **argv) {
    const char *pth = "/tmp/unwritable.conf";

    augeas *aug = aug_init("/", NULL, 0);
    aug_set(aug, "/augeas/load/IniFile/lens", "puppet.lns");
    aug_set(aug, "/augeas/load/IniFile/incl[1]", pth);
    aug_load(aug);

    int fh = open(pth, O_WRONLY|O_CREAT);
    write(fh, "[test]\nkey=0\n", 16);
    close(fh);

    chmod(pth, 0); // with 0644 the file is properly updated

    aug_set(aug, "/files/tmp/unwritable.conf/test/key", "test");

    aug_save(aug);
    aug_close(aug);

    return 0;
 }

Built with:

cc -O test.c -o test -I /usr/local/include -I /usr/local/include/libxml2  -L /usr/local/lib -l augeas

Executed under GDB:

Program received signal SIGSEGV, Segmentation fault.
0x000000080084626f in __aug_close_memstream () from /usr/local/lib/libaugeas.so.0
(gdb) where
#0  0x000000080084626f in __aug_close_memstream () from /usr/local/lib/libaugeas.so.0
#1  0x0000000800845f1f in __aug_close_memstream () from /usr/local/lib/libaugeas.so.0
#2  0x00000008008251b0 in aug_save () from /usr/local/lib/libaugeas.so.0
#3  0x000000080082519e in aug_save () from /usr/local/lib/libaugeas.so.0
#4  0x0000000800824f50 in aug_save () from /usr/local/lib/libaugeas.so.0
#5  0x0000000000400af5 in main ()
(gdb)
@raphink raphink added the bug label Nov 24, 2014
@raphink
Copy link
Member

raphink commented Nov 25, 2014

ping @lutter

@stromnet
Copy link
Author

Just tested, on Debian 7.7 with libaugeas 0.10.0-1 it does not occur, and with manually built 1.3.0 it does not occur either.

Side note:
This issue was found after trying to re-create an situation where python-augeas sometimes reported success and sometimes reported failure, when trying to aug_save() a file which was not writable by the user running the code.

At first glance, before realising that it was bad permissions that was the cause, it looked very similar to what is described in this post: https://www.redhat.com/archives/augeas-devel/2008-November/msg00000.html . I.e, calling save again "seemed" to work (but most likely did not actually update the file).
I was not able to reproduce this on FreeBSD, but found the above instead.

@lutter lutter closed this as completed in 0fb290b Jun 2, 2015
@lutter
Copy link
Member

lutter commented Jun 2, 2015

Thanks for the very thorough bug report (and shame on me for not acting on it earlier)

This is no fixed as of 0fb290b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants