mirror of
https://codeberg.org/scip/pcp.git
synced 2025-12-17 12:00:56 +01:00
added check if input is not binary
This commit is contained in:
@@ -23,6 +23,8 @@
|
|||||||
/* from https://github.com/tlinden/curve-keygen/ */
|
/* from https://github.com/tlinden/curve-keygen/ */
|
||||||
#ifndef _HAVE_PCP_Z85_H
|
#ifndef _HAVE_PCP_Z85_H
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "zmq_z85.h"
|
#include "zmq_z85.h"
|
||||||
#include "mem.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_readz85file(FILE *infile);
|
||||||
char *pcp_readz85string(unsigned char *input, size_t bufsize);
|
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 */
|
#endif /* _HAVE_PCP_Z85_H */
|
||||||
|
|||||||
24
libpcp/z85.c
24
libpcp/z85.c
@@ -22,6 +22,20 @@
|
|||||||
|
|
||||||
#include "z85.h"
|
#include "z85.h"
|
||||||
|
|
||||||
|
size_t _buffer_is_binary(unsigned char *buf, size_t len) {
|
||||||
|
size_t pos;
|
||||||
|
for (pos=0; pos<len; ++pos) {
|
||||||
|
if(buf[pos] == '\0' || (buf[pos] != '\r' && buf[pos] != '\n' && isprint(buf[pos]) == 0)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(pos < len)
|
||||||
|
return pos;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
unsigned char *pcp_padfour(unsigned char *src, size_t srclen, size_t *dstlen) {
|
unsigned char *pcp_padfour(unsigned char *src, size_t srclen, size_t *dstlen) {
|
||||||
size_t outlen, zerolen;
|
size_t outlen, zerolen;
|
||||||
unsigned char *dst;
|
unsigned char *dst;
|
||||||
@@ -145,6 +159,16 @@ char *pcp_readz85string(unsigned char *input, size_t bufsize) {
|
|||||||
int i;
|
int i;
|
||||||
size_t MAXLINE = 1024;
|
size_t MAXLINE = 1024;
|
||||||
|
|
||||||
|
if(bufsize == 0) {
|
||||||
|
fatal("Input file is empty!\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(_buffer_is_binary(input, bufsize) > 0) {
|
||||||
|
fatal("input is not z85 encoded and contains pure binary data");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
Buffer *z = buffer_new(MAXLINE, "z");
|
Buffer *z = buffer_new(MAXLINE, "z");
|
||||||
Buffer *line = buffer_new(MAXLINE, "line");
|
Buffer *line = buffer_new(MAXLINE, "line");
|
||||||
char *oneline;
|
char *oneline;
|
||||||
|
|||||||
Reference in New Issue
Block a user