From 823fc8bbe01c8e5d3fbe1f02bd4a7c45994326c1 Mon Sep 17 00:00:00 2001 From: "git@daemon.de" Date: Thu, 13 Feb 2014 15:30:23 +0100 Subject: [PATCH] added check if input is not binary --- include/pcp/z85.h | 4 ++++ libpcp/z85.c | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/pcp/z85.h b/include/pcp/z85.h index 73d69a2..f3d514b 100644 --- a/include/pcp/z85.h +++ b/include/pcp/z85.h @@ -23,6 +23,8 @@ /* from https://github.com/tlinden/curve-keygen/ */ #ifndef _HAVE_PCP_Z85_H +#include + #include "defines.h" #include "zmq_z85.h" #include "mem.h" @@ -44,4 +46,6 @@ char *pcp_z85_encode(unsigned char *raw, size_t srclen, size_t *dstlen); char *pcp_readz85file(FILE *infile); char *pcp_readz85string(unsigned char *input, size_t bufsize); +size_t _buffer_is_binary(unsigned char *buf, size_t len); + #endif /* _HAVE_PCP_Z85_H */ diff --git a/libpcp/z85.c b/libpcp/z85.c index 3713dd7..55e351c 100644 --- a/libpcp/z85.c +++ b/libpcp/z85.c @@ -22,6 +22,20 @@ #include "z85.h" +size_t _buffer_is_binary(unsigned char *buf, size_t len) { + size_t pos; + for (pos=0; pos 0) { + fatal("input is not z85 encoded and contains pure binary data"); + return NULL; + } + Buffer *z = buffer_new(MAXLINE, "z"); Buffer *line = buffer_new(MAXLINE, "line"); char *oneline;