Skip to content

Commit

Permalink
Fix segfault on attempting to use EditConfigValue() to edit a config …
Browse files Browse the repository at this point in the history
…file on a readonly filesystem.
  • Loading branch information
Subsentient committed Feb 12, 2015
1 parent 77b3460 commit 49db575
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/config.c
Expand Up @@ -2283,7 +2283,17 @@ ReturnCode EditConfigValue(const char *File, const char *ObjectID, const char *A
free(HalfTwo);

/*Write the configuration back to disk.*/
Descriptor = fopen(File, "w");
if (!(Descriptor = fopen(File, "w")))
{
char ErrBuf[2048];
snprintf(ErrBuf, sizeof ErrBuf, "Failed to edit attribute %s for object %s in file %s. File unchanged.",
Attribute, ObjectID, File);

SpitWarning(ErrBuf);
free(MasterStream);
return FAILURE;
}

fwrite(MasterStream, 1, strlen(MasterStream), Descriptor);
fclose(Descriptor);

Expand Down

1 comment on commit 49db575

@Subsentient
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's nobody else for me to blame. I just have to ask the past me: Why would you ever do something so stupid?

Two critical bugs in the config file editing code, both of them caused by hilariously/depressingly obvious mistakes, one of which appears to have been deliberate, for some reason. I found these last two bugs when running Epoch on a 1995 laptop with a stripped down OS.

Please sign in to comment.