Commit 72d00241 by Vicent Marti

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.
parent 92e0b679
...@@ -103,7 +103,6 @@ int git_attr_file__load( ...@@ -103,7 +103,6 @@ int git_attr_file__load(
int error = 0; int error = 0;
git_blob *blob = NULL; git_blob *blob = NULL;
git_buf content = GIT_BUF_INIT; git_buf content = GIT_BUF_INIT;
const char *data = NULL;
git_attr_file *file; git_attr_file *file;
struct stat st; struct stat st;
...@@ -120,7 +119,9 @@ int git_attr_file__load( ...@@ -120,7 +119,9 @@ int git_attr_file__load(
(error = git_blob_lookup(&blob, repo, &id)) < 0) (error = git_blob_lookup(&blob, repo, &id)) < 0)
return error; 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; break;
} }
case GIT_ATTR_FILE__FROM_FILE: { case GIT_ATTR_FILE__FROM_FILE: {
...@@ -143,7 +144,6 @@ int git_attr_file__load( ...@@ -143,7 +144,6 @@ int git_attr_file__load(
if (error < 0) if (error < 0)
return GIT_ENOTFOUND; return GIT_ENOTFOUND;
data = content.ptr;
break; break;
} }
default: default:
...@@ -154,7 +154,7 @@ int git_attr_file__load( ...@@ -154,7 +154,7 @@ int git_attr_file__load(
if ((error = git_attr_file__new(&file, entry, source)) < 0) if ((error = git_attr_file__new(&file, entry, source)) < 0)
goto cleanup; 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); git_attr_file__free(file);
goto cleanup; goto cleanup;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment