commit - f3a5718ad6976d26b5d9c67cbeb73ea10def0990
commit + 3cb9337907f257b2eb23c58f951d0a39407eebe8
blob - b9299840a04fcebccd868e7984bc645a301f2471
blob + 419ff68d2f102e11ebd0fadf20e476be665a59e7
--- lib/buf.c
+++ lib/buf.c
*buf = NULL;
}
return err;
+}
+
+const struct got_error *
+buf_load_fd(BUF **buf, int fd)
+{
+ const struct got_error *err = NULL;
+ unsigned char out[8192];
+ ssize_t r;
+ size_t len;
+
+ err = buf_alloc(buf, 8192);
+ if (err)
+ return err;
+
+ do {
+ r = read(fd, out, sizeof(out));
+ if (r == -1)
+ return got_error_from_errno("read");
+ if (r > 0) {
+ err = buf_append(&len, *buf, out, r);
+ if (err)
+ return err;
+ }
+ } while (r > 0);
+
+ return NULL;
}
void
blob - 354d7c4ea8684b77bc84fa0fcad6b6c8e2b2be80
blob + aff1492306e97d3fdd255c836d083eea96b30e19
--- lib/buf.h
+++ lib/buf.h
const struct got_error *buf_alloc(BUF **, size_t);
const struct got_error *buf_load(BUF **, FILE *);
+const struct got_error *buf_load_fd(BUF **, int fd);
void buf_free(BUF *);
void *buf_release(BUF *);
u_char buf_getc(BUF *, size_t);
blob - bf1781172c3214c0f7cefd4f0294c39c9e986cc0
blob + 3f24aeba16243df7a5bc588249aae2f2551ba93a
--- lib/object_create.c
+++ lib/object_create.c
msg++;
if (signer_id) {
- FILE *out;
pid_t pid;
size_t len;
int in_fd, out_fd;
}
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
err = got_error(GOT_ERR_SIGNING_TAG);
- goto done;
- }
-
- out = fdopen(out_fd, "r");
- if (out == NULL) {
- err = got_error_from_errno("fdopen");
goto done;
}
+
buf_empty(buf);
- err = buf_load(&buf, out);
+ err = buf_load_fd(&buf, out_fd);
if (err)
goto done;
sig_len = buf_len(buf) + 1;
blob - e07362c7af27db964be949901f0ee11c745c0f12
blob + 9303d8b25c0edfd6ef4c036908c27a9606b9bedd
--- lib/sigs.c
+++ lib/sigs.c
} else if (pid == 0) {
if (close(in_pfd[1]) == -1)
err(1, "close");
- if (close(out_pfd[1]) == -1)
+ if (close(out_pfd[0]) == -1)
err(1, "close");
if (dup2(in_pfd[0], 0) == -1)
err(1, "dup2");
- if (dup2(out_pfd[0], 1) == -1)
+ if (dup2(out_pfd[1], 1) == -1)
err(1, "dup2");
if (execv(GOT_TAG_PATH_SSH_KEYGEN, (char **const)argv) == -1)
err(1, "execv");
}
if (close(in_pfd[0]) == -1)
return got_error_from_errno("close");
- if (close(out_pfd[0]) == -1)
+ if (close(out_pfd[1]) == -1)
return got_error_from_errno("close");
*newpid = pid;
*in_fd = in_pfd[1];
- *out_fd = out_pfd[1];
+ *out_fd = out_pfd[0];
return NULL;
}
char* parsed_identity = NULL;
const char *identity;
char* tmppath = NULL;
- FILE *tmpsig, *out = NULL;
+ FILE *tmpsig = NULL;
BUF *buf;
int i = 0, j;
} else if (pid == 0) {
if (close(in_pfd[1]) == -1)
err(1, "close");
- if (close(out_pfd[1]) == -1)
+ if (close(out_pfd[0]) == -1)
err(1, "close");
if (dup2(in_pfd[0], 0) == -1)
err(1, "dup2");
- if (dup2(out_pfd[0], 1) == -1)
+ if (dup2(out_pfd[1], 1) == -1)
err(1, "dup2");
if (execv(GOT_TAG_PATH_SSH_KEYGEN, (char **const)argv) == -1)
err(1, "execv");
error = got_error_from_errno("close");
goto done;
}
- if (close(out_pfd[0]) == -1) {
+ if (close(out_pfd[1]) == -1) {
error = got_error_from_errno("close");
goto done;
}
goto done;
}
- out = fdopen(out_pfd[1], "r");
- if (out == NULL) {
- error = got_error_from_errno("fdopen");
- goto done;
- }
- error = buf_load(&buf, out);
+ error = buf_load_fd(&buf, out_pfd[0]);
if (error)
goto done;
error = buf_putc(buf, '\0');
if (error)
goto done;
- if (close(out_pfd[1]) == -1) {
+ if (close(out_pfd[0]) == -1) {
error = got_error_from_errno("close");
goto done;
}
- out = NULL;
*msg = buf_get(buf);
if (WEXITSTATUS(status) != 0)
error = got_error(GOT_ERR_BAD_TAG_SIGNATURE);
done:
free(parsed_identity);
free(tmppath);
+ close(out_pfd[0]);
if (tmpsig && fclose(tmpsig) == EOF && error == NULL)
error = got_error_from_errno("fclose");
- if (out && fclose(out) == EOF && error == NULL)
- error = got_error_from_errno("fclose");
return error;
}