summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2014-11-21 13:16:42 -0500
committerEdward Thomson <ethomson@edwardthomson.com>2014-11-21 13:16:42 -0500
commite0482934e6187b2e76c0e44960bcbd3ce3795d0c (patch)
treed33b02b3a63fe399e24257653ef225588bf96b6f /src
parent6f4461763eb0518112d22c3a096417e7eedf7385 (diff)
parent24cce2398f893b77f183425fffd957daa3300c5a (diff)
downloadlibgit2-e0482934e6187b2e76c0e44960bcbd3ce3795d0c.tar.gz
Merge pull request #2725 from libgit2/vmg/attr-null
Do not assume blob contents are NULL terminated
Diffstat (limited to 'src')
-rw-r--r--src/attr_file.c8
-rw-r--r--src/buf_text.c1
-rw-r--r--src/buffer.c11
-rw-r--r--src/notes.c3
4 files changed, 13 insertions, 10 deletions
diff --git a/src/attr_file.c b/src/attr_file.c
index e3692cee9..b3efeefd7 100644
--- a/src/attr_file.c
+++ b/src/attr_file.c
@@ -103,7 +103,6 @@ int git_attr_file__load(
int error = 0;
git_blob *blob = NULL;
git_buf content = GIT_BUF_INIT;
- const char *data = NULL;
git_attr_file *file;
struct stat st;
@@ -120,7 +119,9 @@ int git_attr_file__load(
(error = git_blob_lookup(&blob, repo, &id)) < 0)
return error;
- data = git_blob_rawcontent(blob);
+ /* Do not assume that data straight from the ODB is NULL-terminated;
+ * copy the contents of a file to a buffer to work on */
+ git_buf_put(&content, git_blob_rawcontent(blob), git_blob_rawsize(blob));
break;
}
case GIT_ATTR_FILE__FROM_FILE: {
@@ -143,7 +144,6 @@ int git_attr_file__load(
if (error < 0)
return GIT_ENOTFOUND;
- data = content.ptr;
break;
}
default:
@@ -154,7 +154,7 @@ int git_attr_file__load(
if ((error = git_attr_file__new(&file, entry, source)) < 0)
goto cleanup;
- if (parser && (error = parser(repo, file, data)) < 0) {
+ if (parser && (error = parser(repo, file, git_buf_cstr(&content))) < 0) {
git_attr_file__free(file);
goto cleanup;
}
diff --git a/src/buf_text.c b/src/buf_text.c
index 8d2b141b2..cead599f4 100644
--- a/src/buf_text.c
+++ b/src/buf_text.c
@@ -143,6 +143,7 @@ int git_buf_text_lf_to_crlf(git_buf *tgt, const git_buf *src)
tgt->ptr[tgt->size++] = '\n';
}
+ tgt->ptr[tgt->size] = '\0';
return git_buf_put(tgt, scan, end - scan);
}
diff --git a/src/buffer.c b/src/buffer.c
index e9c420e16..7744d8f49 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -176,10 +176,13 @@ int git_buf_putcn(git_buf *buf, char c, size_t len)
int git_buf_put(git_buf *buf, const char *data, size_t len)
{
- ENSURE_SIZE(buf, buf->size + len + 1);
- memmove(buf->ptr + buf->size, data, len);
- buf->size += len;
- buf->ptr[buf->size] = '\0';
+ if (len) {
+ assert(data);
+ ENSURE_SIZE(buf, buf->size + len + 1);
+ memmove(buf->ptr + buf->size, data, len);
+ buf->size += len;
+ buf->ptr[buf->size] = '\0';
+ }
return 0;
}
diff --git a/src/notes.c b/src/notes.c
index 046a91614..4b15925fd 100644
--- a/src/notes.c
+++ b/src/notes.c
@@ -323,11 +323,10 @@ static int note_new(
git_signature_dup(&note->committer, git_commit_committer(commit)) < 0)
return -1;
- note->message = git__strdup((char *)git_blob_rawcontent(blob));
+ note->message = git__strndup(git_blob_rawcontent(blob), git_blob_rawsize(blob));
GITERR_CHECK_ALLOC(note->message);
*out = note;
-
return 0;
}