mirror of
https://github.com/irssi/irssi.git
synced 2026-08-21 09:32:32 +02:00
Fix /save replacing symlinks with regular files
A side-effect of 8deb618 is that `/save` may replace configuration files
that are symlinks with regular files. Fix this by resolving all
symlinks before renaming the temporary file.
This commit is contained in:
parent
85df01d133
commit
764f8215a9
1 changed files with 11 additions and 1 deletions
|
|
@ -304,6 +304,7 @@ int config_write(CONFIG_REC *rec, const char *fname, int create_mode)
|
||||||
int save_errno;
|
int save_errno;
|
||||||
char *tmp_name;
|
char *tmp_name;
|
||||||
const char *dest_name;
|
const char *dest_name;
|
||||||
|
char *real_dest = NULL;
|
||||||
|
|
||||||
g_return_val_if_fail(rec != NULL, -1);
|
g_return_val_if_fail(rec != NULL, -1);
|
||||||
g_return_val_if_fail(fname != NULL || rec->fname != NULL, -1);
|
g_return_val_if_fail(fname != NULL || rec->fname != NULL, -1);
|
||||||
|
|
@ -349,7 +350,15 @@ int config_write(CONFIG_REC *rec, const char *fname, int create_mode)
|
||||||
g_io_channel_unref(rec->handle);
|
g_io_channel_unref(rec->handle);
|
||||||
rec->handle = NULL;
|
rec->handle = NULL;
|
||||||
|
|
||||||
if (rename(tmp_name, dest_name) == -1) {
|
/* expand all symlinks; else we may replace a symlink with a regular file */
|
||||||
|
real_dest = realpath(dest_name, NULL);
|
||||||
|
if (real_dest == NULL) {
|
||||||
|
unlink(tmp_name);
|
||||||
|
config_error(rec, g_strerror(errno));
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rename(tmp_name, real_dest) == -1) {
|
||||||
unlink(tmp_name);
|
unlink(tmp_name);
|
||||||
config_error(rec, g_strerror(errno));
|
config_error(rec, g_strerror(errno));
|
||||||
goto out;
|
goto out;
|
||||||
|
|
@ -362,6 +371,7 @@ out:
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free(tmp_name);
|
g_free(tmp_name);
|
||||||
|
g_free(real_dest);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue