From: Steven Michalske <smichalske@gmail.com>
To: git@vger.kernel.org
Cc: Steven Michalske <smichalske@gmail.com>
Subject: [PATCH] Use strncpy to protect from buffer overruns.
Date: Wed, 9 Jun 2010 03:22:01 -0700 [thread overview]
Message-ID: <1276078921-25429-1-git-send-email-smichalske@gmail.com> (raw)
is_git_directory() uses strcpy with pointer arithmitic, protect it from
overflowing. Even though we currently protect higher up when we have the
environment variable path passed in, we should protect the calls here.
Signed-off-by: Steven Michalske <smichalske@gmail.com>
---
setup.c | 10 ++++++----
1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/setup.c b/setup.c
index 7e04602..0080299 100644
--- a/setup.c
+++ b/setup.c
@@ -170,22 +170,24 @@ static int is_git_directory(const char *suspect)
char path[PATH_MAX];
size_t len = strlen(suspect);
- strcpy(path, suspect);
+ path[sizeof(path) - 1] = '\0';
+
+ strncpy(path, suspect, sizeof(path) - 1);
if (getenv(DB_ENVIRONMENT)) {
if (access(getenv(DB_ENVIRONMENT), X_OK))
return 0;
}
else {
- strcpy(path + len, "/objects");
+ strncpy(path + len, "/objects", sizeof(path) - len - 1);
if (access(path, X_OK))
return 0;
}
- strcpy(path + len, "/refs");
+ strncpy(path + len, "/refs", sizeof(path) - len - 1);
if (access(path, X_OK))
return 0;
- strcpy(path + len, "/HEAD");
+ strncpy(path + len, "/HEAD", sizeof(path) - len - 1);
if (validate_headref(path))
return 0;
--
1.7.0.3
next reply other threads:[~2010-06-09 10:22 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-09 10:22 Steven Michalske [this message]
2010-06-09 12:44 ` [PATCH] Use strncpy to protect from buffer overruns Alex Riesen
2010-06-09 18:25 ` Steven Michalske
2010-06-09 19:31 ` Alex Riesen
2010-06-09 20:42 ` Steven Michalske
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=1276078921-25429-1-git-send-email-smichalske@gmail.com \
--to=smichalske@gmail.com \
--cc=git@vger.kernel.org \
/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).