summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2014-11-21 13:32:21 +0100
committerVicent Marti <tanoku@gmail.com>2014-11-21 17:21:34 +0100
commit72d0024134a532374e7fa17ae9e5b6b021ffe324 (patch)
tree811c204bd6c1f23080a6981fc865ab7d8e82673d
parent92e0b67930f350a40575954f4638cbc71fee57d2 (diff)
downloadlibgit2-72d0024134a532374e7fa17ae9e5b6b021ffe324.tar.gz
attr_file: Do not assume ODB data is NULL-terminated
That's a bad assumption to make, even though right now it holds (because of the way we've implemented decompression of packfiles), this may change in the future, given that ODB objects can be binary data. Furthermore, the ODB object can return a NULL pointer if the object is empty. Copying the NULL pointer to the strbuf lets us handle it like an empty string. Again, the NULL pointer is valid behavior because you're supposed to check the *size* of the object before working on it.
-rw-r--r--src/attr_file.c8
1 files changed, 4 insertions, 4 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;
}