fixed utf8 bug, which sometimes lead to z85 handling of pure binary data

This commit is contained in:
TLINDEN
2014-03-17 19:15:04 +01:00
parent 322a135ee3
commit b6dadceda3
3 changed files with 6 additions and 2 deletions

View File

@@ -8,6 +8,7 @@ extern "C" {
#include "pcp/config.h"
#include "pcp/base85.h"
#include "pcp/buffer.h"
#include "pcp/config.h"
#include "pcp/crypto.h"
#include "pcp/defines.h"
#include "pcp/digital_crc32.h"

View File

@@ -331,6 +331,7 @@ void ps_determine(Pcpstream *stream) {
/* check if it's binary or not */
if(_buffer_is_binary(buf, got) == 0) {
/* not binary, it's armored */
stream->armor = 1;

View File

@@ -101,7 +101,6 @@ size_t _buffer_is_binary(byte *buf, size_t len) {
for (pos=1; pos<len; ++pos) {
if(buf[pos] == '\0' || (buf[pos] != '\r' && buf[pos] != '\n' && isprint(buf[pos]) == 0)) {
/* it's probably a binary char */
/* check for utf8 */
wide[0] = buf[pos];
for(i=1; i<3; i++) {
@@ -112,20 +111,23 @@ size_t _buffer_is_binary(byte *buf, size_t len) {
if(is_utf8(wide) > 1) {
pos += i; /* jump over the utf we already found */
utf = 1;
break;
}
}
else
break;
}
memset(wide, 0, 4);
if(utf == 1) {
/* it's a utf8 char, continue checking, reset wide */
memset(wide, 0, 4);
utf = 0;
continue;
}
break; /* if we reach this, then it's binary and not utf8, stop checking */
}
}
if(pos < len)
return pos; /* binary */
else