Skip to content

Commit

Permalink
don't dereference NULL upon fdopen failure
Browse files Browse the repository at this point in the history
There were several unchecked use of fdopen(); replace them with xfdopen()
that checks and dies.

Signed-off-by: Jim Meyering <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
Jim Meyering authored and gitster committed Sep 13, 2009
1 parent 3d91352 commit 4169837
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion builtin-add.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ static int edit_patch(int argc, const char **argv, const char *prefix)
out = open(file, O_CREAT | O_WRONLY, 0644);
if (out < 0)
die ("Could not open '%s' for writing.", file);
rev.diffopt.file = fdopen(out, "w");
rev.diffopt.file = xfdopen(out, "w");
rev.diffopt.close_file = 1;
if (run_diff_files(&rev, 0))
die ("Could not write patch");
Expand Down
2 changes: 1 addition & 1 deletion builtin-mailsplit.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static int split_one(FILE *mbox, const char *name, int allow_bare)
fd = open(name, O_WRONLY | O_CREAT | O_EXCL, 0666);
if (fd < 0)
die_errno("cannot open output file '%s'", name);
output = fdopen(fd, "w");
output = xfdopen(fd, "w");

/* Copy it out, while searching for a line that begins with
* "From " and having something that looks like a date format.
Expand Down
2 changes: 1 addition & 1 deletion bundle.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ int create_bundle(struct bundle_header *header, const char *path,
rls.git_cmd = 1;
if (start_command(&rls))
return -1;
rls_fout = fdopen(rls.out, "r");
rls_fout = xfdopen(rls.out, "r");
while (fgets(buffer, sizeof(buffer), rls_fout)) {
unsigned char sha1[20];
if (buffer[0] == '-') {
Expand Down
6 changes: 3 additions & 3 deletions transport-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static struct child_process *get_helper(struct transport *transport)

write_str_in_full(helper->in, "capabilities\n");

file = fdopen(helper->out, "r");
file = xfdopen(helper->out, "r");
while (1) {
if (strbuf_getline(&buf, file, '\n') == EOF)
exit(128); /* child died, message supplied already */
Expand Down Expand Up @@ -71,7 +71,7 @@ static int fetch_with_fetch(struct transport *transport,
int nr_heads, const struct ref **to_fetch)
{
struct child_process *helper = get_helper(transport);
FILE *file = fdopen(helper->out, "r");
FILE *file = xfdopen(helper->out, "r");
int i;
struct strbuf buf = STRBUF_INIT;

Expand Down Expand Up @@ -124,7 +124,7 @@ static struct ref *get_refs_list(struct transport *transport, int for_push)

write_str_in_full(helper->in, "list\n");

file = fdopen(helper->out, "r");
file = xfdopen(helper->out, "r");
while (1) {
char *eov, *eon;
if (strbuf_getline(&buf, file, '\n') == EOF)
Expand Down
4 changes: 2 additions & 2 deletions upload-pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static int do_rev_list(int fd, void *create_full_pack)
int i;
struct rev_info revs;

pack_pipe = fdopen(fd, "w");
pack_pipe = xfdopen(fd, "w");
init_revisions(&revs, NULL);
revs.tag_objects = 1;
revs.tree_objects = 1;
Expand Down Expand Up @@ -255,7 +255,7 @@ static void create_pack_file(void)

/* pass on revisions we (don't) want */
if (!shallow_nr) {
FILE *pipe_fd = fdopen(pack_objects.in, "w");
FILE *pipe_fd = xfdopen(pack_objects.in, "w");
if (!create_full_pack) {
int i;
for (i = 0; i < want_obj.nr; i++)
Expand Down

0 comments on commit 4169837

Please sign in to comment.