From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Cc: Jon Griffiths <jon_p_griffiths@yahoo.com>
Subject: [PATCH 1/3] credential-cache--daemon: refactor check_socket_directory
Date: Tue, 23 Feb 2016 02:15:15 -0500 [thread overview]
Message-ID: <20160223071515.GA8395@sigill.intra.peff.net> (raw)
In-Reply-To: <20160223071427.GA7489@sigill.intra.peff.net>
From: Jon Griffiths <jon_p_griffiths@yahoo.com>
This function does an early return, and therefore has to
repeat its cleanup. We can stick the later bit of the
function into an "else" and avoid duplicating the shared
part (which will get bigger in a future patch).
Let's also rename the function to init_socket_directory. It
not only checks the directory but also creates it. Saying
"init" is more accurate.
Signed-off-by: Jon Griffiths <jon_p_griffiths@yahoo.com>
Signed-off-by: Jeff King <peff@peff.net>
---
credential-cache--daemon.c | 28 +++++++++++++---------------
1 file changed, 13 insertions(+), 15 deletions(-)
diff --git a/credential-cache--daemon.c b/credential-cache--daemon.c
index cc65a9c..3403f48 100644
--- a/credential-cache--daemon.c
+++ b/credential-cache--daemon.c
@@ -215,7 +215,7 @@ static const char permissions_advice[] =
"users may be able to read your cached credentials. Consider running:\n"
"\n"
" chmod 0700 %s";
-static void check_socket_directory(const char *path)
+static void init_socket_directory(const char *path)
{
struct stat st;
char *path_copy = xstrdup(path);
@@ -224,20 +224,18 @@ static void check_socket_directory(const char *path)
if (!stat(dir, &st)) {
if (st.st_mode & 077)
die(permissions_advice, dir);
- free(path_copy);
- return;
+ } else {
+ /*
+ * We must be sure to create the directory with the correct mode,
+ * not just chmod it after the fact; otherwise, there is a race
+ * condition in which somebody can chdir to it, sleep, then try to open
+ * our protected socket.
+ */
+ if (safe_create_leading_directories_const(dir) < 0)
+ die_errno("unable to create directories for '%s'", dir);
+ if (mkdir(dir, 0700) < 0)
+ die_errno("unable to mkdir '%s'", dir);
}
-
- /*
- * We must be sure to create the directory with the correct mode,
- * not just chmod it after the fact; otherwise, there is a race
- * condition in which somebody can chdir to it, sleep, then try to open
- * our protected socket.
- */
- if (safe_create_leading_directories_const(dir) < 0)
- die_errno("unable to create directories for '%s'", dir);
- if (mkdir(dir, 0700) < 0)
- die_errno("unable to mkdir '%s'", dir);
free(path_copy);
}
@@ -264,7 +262,7 @@ int main(int argc, const char **argv)
if (!socket_path)
usage_with_options(usage, options);
- check_socket_directory(socket_path);
+ init_socket_directory(socket_path);
register_tempfile(&socket_file, socket_path);
if (ignore_sighup)
--
2.7.2.645.g4e1306c
next prev parent reply other threads:[~2016-02-23 7:15 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-23 7:14 [PATCH 0/3] credential-cache: give daemon a predictable cwd Jeff King
2016-02-23 7:15 ` Jeff King [this message]
2016-02-23 7:15 ` [PATCH 2/3] credential-cache--daemon: disallow relative socket path Jeff King
2016-02-23 7:16 ` [PATCH 3/3] credential-cache--daemon: change to the socket dir on startup Jeff King
2016-02-23 21:06 ` Junio C Hamano
2016-02-23 21:07 ` Jeff King
2016-02-23 21:09 ` Junio C Hamano
2016-02-23 21:10 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160223071515.GA8395@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=jon_p_griffiths@yahoo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).