Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 4169837

Browse files
Jim Meyeringgitster
Jim Meyering
authored andcommitted
don't dereference NULL upon fdopen failure
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]>
1 parent 3d91352 commit 4169837

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

builtin-add.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ static int edit_patch(int argc, const char **argv, const char *prefix)
198198
out = open(file, O_CREAT | O_WRONLY, 0644);
199199
if (out < 0)
200200
die ("Could not open '%s' for writing.", file);
201-
rev.diffopt.file = fdopen(out, "w");
201+
rev.diffopt.file = xfdopen(out, "w");
202202
rev.diffopt.close_file = 1;
203203
if (run_diff_files(&rev, 0))
204204
die ("Could not write patch");

builtin-mailsplit.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static int split_one(FILE *mbox, const char *name, int allow_bare)
6464
fd = open(name, O_WRONLY | O_CREAT | O_EXCL, 0666);
6565
if (fd < 0)
6666
die_errno("cannot open output file '%s'", name);
67-
output = fdopen(fd, "w");
67+
output = xfdopen(fd, "w");
6868

6969
/* Copy it out, while searching for a line that begins with
7070
* "From " and having something that looks like a date format.

bundle.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ int create_bundle(struct bundle_header *header, const char *path,
234234
rls.git_cmd = 1;
235235
if (start_command(&rls))
236236
return -1;
237-
rls_fout = fdopen(rls.out, "r");
237+
rls_fout = xfdopen(rls.out, "r");
238238
while (fgets(buffer, sizeof(buffer), rls_fout)) {
239239
unsigned char sha1[20];
240240
if (buffer[0] == '-') {

transport-helper.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static struct child_process *get_helper(struct transport *transport)
3939

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

42-
file = fdopen(helper->out, "r");
42+
file = xfdopen(helper->out, "r");
4343
while (1) {
4444
if (strbuf_getline(&buf, file, '\n') == EOF)
4545
exit(128); /* child died, message supplied already */
@@ -71,7 +71,7 @@ static int fetch_with_fetch(struct transport *transport,
7171
int nr_heads, const struct ref **to_fetch)
7272
{
7373
struct child_process *helper = get_helper(transport);
74-
FILE *file = fdopen(helper->out, "r");
74+
FILE *file = xfdopen(helper->out, "r");
7575
int i;
7676
struct strbuf buf = STRBUF_INIT;
7777

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

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

127-
file = fdopen(helper->out, "r");
127+
file = xfdopen(helper->out, "r");
128128
while (1) {
129129
char *eov, *eon;
130130
if (strbuf_getline(&buf, file, '\n') == EOF)

upload-pack.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static int do_rev_list(int fd, void *create_full_pack)
108108
int i;
109109
struct rev_info revs;
110110

111-
pack_pipe = fdopen(fd, "w");
111+
pack_pipe = xfdopen(fd, "w");
112112
init_revisions(&revs, NULL);
113113
revs.tag_objects = 1;
114114
revs.tree_objects = 1;
@@ -255,7 +255,7 @@ static void create_pack_file(void)
255255

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

0 commit comments

Comments
 (0)