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 <meyering@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jim Meyering committed
Sep 12, 2009 at 10:43 UTC
41698375ada57d51cf6db5cf25970ccd1b918180
5 files changed
+8
-8
builtin-add.c
+1
-1
@@ -198,7 +198,7 @@ static int edit_patch(int argc, const char **argv, const char *prefix)
198
out = open(file, O_CREAT | O_WRONLY, 0644);
199
if (out < 0)
200
die ("Could not open '%s' for writing.", file);
201
- rev.diffopt.file = fdopen(out, "w");
201
+ rev.diffopt.file = xfdopen(out, "w");
202
rev.diffopt.close_file = 1;
203
if (run_diff_files(&rev, 0))
204
die ("Could not write patch");
builtin-mailsplit.c
+1
-1
@@ -64,7 +64,7 @@ static int split_one(FILE *mbox, const char *name, int allow_bare)
64
fd = open(name, O_WRONLY | O_CREAT | O_EXCL, 0666);
65
if (fd < 0)
66
die_errno("cannot open output file '%s'", name);
67
- output = fdopen(fd, "w");
67
+ output = xfdopen(fd, "w");
68
69
/* Copy it out, while searching for a line that begins with
70
* "From " and having something that looks like a date format.
bundle.c
+1
-1
@@ -234,7 +234,7 @@ int create_bundle(struct bundle_header *header, const char *path,
234
rls.git_cmd = 1;
235
if (start_command(&rls))
236
return -1;
237
- rls_fout = fdopen(rls.out, "r");
237
+ rls_fout = xfdopen(rls.out, "r");
238
while (fgets(buffer, sizeof(buffer), rls_fout)) {
239
unsigned char sha1[20];
240
if (buffer[0] == '-') {
transport-helper.c
+3
-3
@@ -39,7 +39,7 @@ static struct child_process *get_helper(struct transport *transport)
39
40
write_str_in_full(helper->in, "capabilities\n");
41
42
- file = fdopen(helper->out, "r");
42
+ file = xfdopen(helper->out, "r");
43
while (1) {
44
if (strbuf_getline(&buf, file, '\n') == EOF)
45
exit(128); /* child died, message supplied already */
@@ -71,7 +71,7 @@ static int fetch_with_fetch(struct transport *transport,
71
int nr_heads, const struct ref **to_fetch)
72
{
73
struct child_process *helper = get_helper(transport);
74
- FILE *file = fdopen(helper->out, "r");
74
+ FILE *file = xfdopen(helper->out, "r");
75
int i;
76
struct strbuf buf = STRBUF_INIT;
77
@@ -124,7 +124,7 @@ static struct ref *get_refs_list(struct transport *transport, int for_push)
124
125
write_str_in_full(helper->in, "list\n");
126
127
- file = fdopen(helper->out, "r");
127
+ file = xfdopen(helper->out, "r");
128
while (1) {
129
char *eov, *eon;
130
if (strbuf_getline(&buf, file, '\n') == EOF)
upload-pack.c
+2
-2
@@ -108,7 +108,7 @@ static int do_rev_list(int fd, void *create_full_pack)
108
int i;
109
struct rev_info revs;
110
111
- pack_pipe = fdopen(fd, "w");
111
+ pack_pipe = xfdopen(fd, "w");
112
init_revisions(&revs, NULL);
113
revs.tag_objects = 1;
114
revs.tree_objects = 1;
@@ -255,7 +255,7 @@ static void create_pack_file(void)
255
256
/* pass on revisions we (don't) want */
257
if (!shallow_nr) {
258
- FILE *pipe_fd = fdopen(pack_objects.in, "w");
258
+ FILE *pipe_fd = xfdopen(pack_objects.in, "w");
259
if (!create_full_pack) {
260
int i;
261
for (i = 0; i < want_obj.nr; i++)