From: Tomi Ollila Date: Sun, 3 Mar 2013 18:38:52 +0000 (+0200) Subject: Re: [PATCH v3] config: do not overwrite symlinks when saving config file X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d5b611915325b12c1cdefbe26295279b20371f0d;p=notmuch-archives.git Re: [PATCH v3] config: do not overwrite symlinks when saving config file --- diff --git a/a7/baabb3883778c8c92ddab0628c93143d1d46c0 b/a7/baabb3883778c8c92ddab0628c93143d1d46c0 new file mode 100644 index 000000000..1fd6c05a4 --- /dev/null +++ b/a7/baabb3883778c8c92ddab0628c93143d1d46c0 @@ -0,0 +1,129 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id D9E74431FAF + for ; Sun, 3 Mar 2013 10:39:06 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0 +X-Spam-Level: +X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] + autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id 2wtAZ8CICSdO for ; + Sun, 3 Mar 2013 10:39:05 -0800 (PST) +Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) + by olra.theworths.org (Postfix) with ESMTP id 5E954431FAE + for ; Sun, 3 Mar 2013 10:39:05 -0800 (PST) +Received: from guru.guru-group.fi (localhost [IPv6:::1]) + by guru.guru-group.fi (Postfix) with ESMTP id 38407100051; + Sun, 3 Mar 2013 20:38:53 +0200 (EET) +From: Tomi Ollila +To: Jani Nikula , notmuch@notmuchmail.org +Subject: Re: [PATCH v3] config: do not overwrite symlinks when saving config + file +In-Reply-To: <1362320310-10930-1-git-send-email-jani@nikula.org> +References: + <1362320310-10930-1-git-send-email-jani@nikula.org> +User-Agent: Notmuch/0.15.2+48~g8dcc33e (http://notmuchmail.org) Emacs/24.2.1 + (x86_64-unknown-linux-gnu) +X-Face: HhBM'cA~ +MIME-Version: 1.0 +Content-Type: text/plain +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sun, 03 Mar 2013 18:39:07 -0000 + +On Sun, Mar 03 2013, Jani Nikula wrote: + +> Use realpath to canonicalize the config path before writing. +> +> Previously 'notmuch setup' and 'notmuch config set' overwrote the +> config file even if it was a symbolic link. +> +> --- +> +> v3: compared to v2, as suggested by Tomi on IRC: +> +> - if (strcmp (filename, config->filename)) { +> + if (strcmp (filename, config->filename) != 0) { + + +LGTM. + +Tomi + +> --- +> notmuch-config.c | 24 ++++++++++++++++++++---- +> 1 file changed, 20 insertions(+), 4 deletions(-) +> +> diff --git a/notmuch-config.c b/notmuch-config.c +> index b5c2066..8adb404 100644 +> --- a/notmuch-config.c +> +++ b/notmuch-config.c +> @@ -461,7 +461,7 @@ int +> notmuch_config_save (notmuch_config_t *config) +> { +> size_t length; +> - char *data; +> + char *data, *filename; +> GError *error = NULL; +> +> data = g_key_file_to_data (config->key_file, &length, NULL); +> @@ -470,14 +470,30 @@ notmuch_config_save (notmuch_config_t *config) +> return 1; +> } +> +> - if (! g_file_set_contents (config->filename, data, length, &error)) { +> - fprintf (stderr, "Error saving configuration to %s: %s\n", +> - config->filename, error->message); +> + /* Try not to overwrite symlinks. */ +> + filename = realpath (config->filename, NULL); +> + if (! filename) { +> + fprintf (stderr, "Error canonicalizing %s: %s\n", config->filename, +> + strerror (errno)); +> + g_free (data); +> + return 1; +> + } +> + +> + if (! g_file_set_contents (filename, data, length, &error)) { +> + if (strcmp (filename, config->filename) != 0) { +> + fprintf (stderr, "Error saving configuration to %s (-> %s): %s\n", +> + config->filename, filename, error->message); +> + } else { +> + fprintf (stderr, "Error saving configuration to %s: %s\n", +> + filename, error->message); +> + } +> g_error_free (error); +> + free (filename); +> g_free (data); +> return 1; +> } +> +> + free (filename); +> g_free (data); +> return 0; +> } +> -- +> 1.7.10.4 +> +> _______________________________________________ +> notmuch mailing list +> notmuch@notmuchmail.org +> http://notmuchmail.org/mailman/listinfo/notmuch