diff options
author | Martin Willi <martin@revosec.ch> | 2013-11-21 12:19:20 +0100 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2014-01-23 15:55:32 +0100 |
commit | 1c4a3459f72da4391c1befe22e62356d838af46d (patch) | |
tree | a60e5be4cf8c95c05b891f84df5ffa1069ec65ef /src/pki/commands/self.c | |
parent | 595b6d9a828538072dcf65c276b848a02698fdfe (diff) | |
download | strongswan-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/self.c')
-rw-r--r-- | src/pki/commands/self.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/pki/commands/self.c b/src/pki/commands/self.c index 6bf0b1353..c28c9c291 100644 --- a/src/pki/commands/self.c +++ b/src/pki/commands/self.c @@ -14,6 +14,7 @@ */ #include <time.h> +#include <errno.h> #include "pki.h" @@ -273,7 +274,12 @@ static int self() { chunk_t chunk; - chunk = chunk_from_fd(0); + if (!chunk_from_fd(0, &chunk)) + { + fprintf(stderr, "%s: ", strerror(errno)); + error = "reading private key failed"; + goto end; + } private = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, type, BUILD_BLOB, chunk, BUILD_END); free(chunk.ptr); |