From: Carlos Rica <jasampler@gmail.com>
To: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: [PATCH] Fix git_mkstemp to return an error when path is too long.
Date: Thu, 26 Jul 2007 03:32:52 +0200 [thread overview]
Message-ID: <46A7F9C4.7030004@gmail.com> (raw)
Now the function returns -2 to the caller if the given buffer
is too short to save the entire path for the temporary file.
Signed-off-by: Carlos Rica <jasampler@gmail.com>
---
diff.c | 2 ++
path.c | 9 ++++++---
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/diff.c b/diff.c
index cd6b0c4..8735467 100644
--- a/diff.c
+++ b/diff.c
@@ -1694,6 +1694,8 @@ static void prep_temp_blob(struct diff_tempfile *temp,
int fd;
fd = git_mkstemp(temp->tmp_path, PATH_MAX, ".diff_XXXXXX");
+ if (fd == -2)
+ die("path too long for temp-file");
if (fd < 0)
die("unable to create temp-file");
if (write_in_full(fd, blob, size) != size)
diff --git a/path.c b/path.c
index c4ce962..f33d15d 100644
--- a/path.c
+++ b/path.c
@@ -68,7 +68,8 @@ char *git_path(const char *fmt, ...)
}
-/* git_mkstemp() - create tmp file honoring TMPDIR variable */
+/* git_mkstemp() - create tmp file honoring TMPDIR variable.
+ * return -2 if path is too long to have it concatenated. */
int git_mkstemp(char *path, size_t len, const char *template)
{
char *env, *pch = path;
@@ -79,12 +80,14 @@ int git_mkstemp(char *path, size_t len, const char *template)
pch += 5;
} else {
size_t n = snprintf(pch, len, "%s/", env);
-
+ if (n >= len)
+ return -2;
len -= n;
pch += n;
}
- strlcpy(pch, template, len);
+ if (strlcpy(pch, template, len) >= len)
+ return -2;
return mkstemp(path);
}
--
1.5.0
next reply other threads:[~2007-07-26 1:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-26 1:32 Carlos Rica [this message]
2007-07-26 3:36 ` [PATCH] Fix git_mkstemp to return an error when path is too long Johannes Schindelin
2007-07-26 4:26 ` Junio C Hamano
2007-07-26 19:42 ` Carlos Rica
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=46A7F9C4.7030004@gmail.com \
--to=jasampler@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.