aboutsummaryrefslogtreecommitdiffstats
path: root/src/pki/commands/issue.c
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2013-11-21 12:19:20 +0100
committerMartin Willi <martin@revosec.ch>2014-01-23 15:55:32 +0100
commit1c4a3459f72da4391c1befe22e62356d838af46d (patch)
treea60e5be4cf8c95c05b891f84df5ffa1069ec65ef /src/pki/commands/issue.c
parent595b6d9a828538072dcf65c276b848a02698fdfe (diff)
downloadstrongswan-1c4a3459f72da4391c1befe22e62356d838af46d.tar.bz2
strongswan-1c4a3459f72da4391c1befe22e62356d838af46d.tar.xz
chunk: Use dynamically allocated buffer in chunk_from_fd()
When acting on files, we can use fstat() to estimate the buffer size. On non-file FDs, we dynamically increase an allocated buffer. Additionally we slightly change the function signature to properly handle zero-length files and add appropriate unit tests.
Diffstat (limited to 'src/pki/commands/issue.c')
-rw-r--r--src/pki/commands/issue.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/pki/commands/issue.c b/src/pki/commands/issue.c
index 000f63d1a..d5c33b89f 100644
--- a/src/pki/commands/issue.c
+++ b/src/pki/commands/issue.c
@@ -14,6 +14,7 @@
*/
#include <time.h>
+#include <errno.h>
#include "pki.h"
@@ -382,7 +383,12 @@ static int issue()
{
chunk_t chunk;
- chunk = chunk_from_fd(0);
+ if (!chunk_from_fd(0, &chunk))
+ {
+ fprintf(stderr, "%s: ", strerror(errno));
+ error = "reading certificate request failed";
+ goto end;
+ }
cert_req = lib->creds->create(lib->creds, CRED_CERTIFICATE,
CERT_PKCS10_REQUEST,
BUILD_BLOB, chunk, BUILD_END);
@@ -425,7 +431,12 @@ static int issue()
{
chunk_t chunk;
- chunk = chunk_from_fd(0);
+ if (!chunk_from_fd(0, &chunk))
+ {
+ fprintf(stderr, "%s: ", strerror(errno));
+ error = "reading public key failed";
+ goto end;
+ }
public = lib->creds->create(lib->creds, CRED_PUBLIC_KEY, KEY_ANY,
BUILD_BLOB, chunk, BUILD_END);
free(chunk.ptr);
@@ -562,4 +573,3 @@ static void __attribute__ ((constructor))reg()
}
});
}
-