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.
This commit is contained in:
@@ -13,6 +13,8 @@
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "pki.h"
|
||||
|
||||
#include <credentials/certificates/certificate.h>
|
||||
@@ -89,7 +91,11 @@ static int keyid()
|
||||
{
|
||||
chunk_t chunk;
|
||||
|
||||
chunk = chunk_from_fd(0);
|
||||
if (!chunk_from_fd(0, &chunk))
|
||||
{
|
||||
fprintf(stderr, "reading input failed: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
cred = lib->creds->create(lib->creds, type, subtype,
|
||||
BUILD_BLOB, chunk, BUILD_END);
|
||||
free(chunk.ptr);
|
||||
@@ -165,4 +171,3 @@ static void __attribute__ ((constructor))reg()
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user