commit - 15d3ea5655eca208cfecf4e42d2f3dbda1842eff
commit + d5003b790484caa6509175907d44dedd373b59d3
blob - 23a4cf3f57651c3cf747e03f36514dcb571733e6
blob + 425c26d14098f9f28e48521cb347a23089a2264d
--- lib/object.c
+++ lib/object.c
}
static const struct got_error *
-open_loose_object(FILE **f, struct got_object *obj, struct got_repository *repo)
+open_loose_object(int *fd, struct got_object *obj, struct got_repository *repo)
{
const struct got_error *err = NULL;
char *path;
err = object_path(&path, &obj->id, repo);
if (err)
return err;
- *f = fopen(path, "rb");
- if (*f == NULL) {
+ *fd = open(path, O_RDONLY | O_NOFOLLOW, GOT_DEFAULT_FILE_MODE);
+ if (*fd == -1) {
err = got_error_from_errno();
goto done;
}
free(buf);
} else {
FILE *f;
- err = open_loose_object(&f, obj, repo);
+ int fd;
+ err = open_loose_object(&fd, obj, repo);
if (err)
return err;
+ f = fdopen(fd, "rb");
+ if (f == NULL) {
+ err = got_error_from_errno();
+ close(fd);
+ return err;
+ }
err = read_commit_object(commit, repo, obj, f);
fclose(f);
}
free(buf);
} else {
FILE *f;
- err = open_loose_object(&f, obj, repo);
+ int fd;
+ err = open_loose_object(&fd, obj, repo);
if (err)
return err;
+ f = fdopen(fd, "rb");
+ if (f == NULL) {
+ close(fd);
+ return got_error_from_errno();
+ }
err = read_tree_object(tree, repo, obj, f);
fclose(f);
+ close(fd);
}
return err;
}
return err;
}
} else {
- err = open_loose_object(&((*blob)->f), obj, repo);
+ int fd;
+ err = open_loose_object(&fd, obj, repo);
if (err) {
free(*blob);
*blob = NULL;
return err;
}
+ (*blob)->f = fdopen(fd, "rb");
+ if ((*blob)->f == NULL) {
+ free(*blob);
+ *blob = NULL;
+ close(fd);
+ return err;
+ }
err = got_inflate_init(&(*blob)->zb, NULL, blocksize);
if (err != NULL) {