Skip to content

Commit

Permalink
Fix for 'last character missing' issue with user-inputed strings, lik…
Browse files Browse the repository at this point in the history
…e network passphrases
  • Loading branch information
ColumPaget committed Apr 30, 2020
1 parent d5f11b6 commit 54441b8
Show file tree
Hide file tree
Showing 15 changed files with 96 additions and 72 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=1.2
VERSION=1.1
CC=gcc
LIBS= libUseful-4/libUseful.a
FLAGS=-g -O2 -DVERSION=\"$(VERSION)\"
Expand Down
2 changes: 1 addition & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=1.1
VERSION=1.3
CC=@CC@
LIBS=@LDFLAGS@ @LIBS@ @STATIC_LIBS@
FLAGS=@CFLAGS@ -DVERSION=\"$(VERSION)\"
Expand Down
41 changes: 15 additions & 26 deletions config.log
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ generated by GNU Autoconf 2.69. Invocation command line was
## Platform. ##
## --------- ##

hostname = DellM6400
uname -m = x86_64
hostname = lifebook3
uname -m = i486
uname -r = 5.6.5-64
uname -s = Linux
uname -v = #6 SMP Sun Apr 19 22:31:45 BST 2020

/usr/bin/uname -p = unknown
/bin/uname -X = unknown
/bin/uname -X =

/bin/arch = unknown
/usr/bin/arch -k = unknown
Expand All @@ -39,37 +39,26 @@ PATH: /opt/Drawing/bin
PATH: /opt/FLTK/bin
PATH: /opt/GTK/bin
PATH: /opt/LibreCAD/bin
PATH: /opt/Python-2.7.15/bin
PATH: /opt/Python-3.5.6/bin
PATH: /opt/Qt5/bin
PATH: /opt/SDL/bin
PATH: /opt/SDL2/bin
PATH: /opt/blender-2.79b/bin
PATH: /opt/brlcad-7.26.4/bin
PATH: /opt/chess/bin
PATH: /opt/clamav-0.100.1/bin
PATH: /opt/games/bin
PATH: /opt/gdbm-1.18.1/bin
PATH: /opt/ghostscript-9.26/bin
PATH: /opt/ghostscript-9.28rc2/bin
PATH: /opt/gifprogs-5.1.2/bin
PATH: /opt/git-2.21.0/bin
PATH: /opt/graphviz-2.40.1/bin
PATH: /opt/jpegprogs-9c/bin
PATH: /opt/git-2.20.1/bin
PATH: /opt/lua-5.3.4/bin
PATH: /opt/luajid-2.0.4/bin
PATH: /opt/mono-5.20.1.27/bin
PATH: /opt/mujs-1.0.5/bin
PATH: /opt/netpbm-10.66.02/bin
PATH: /opt/ogre-3d/bin
PATH: /opt/opengl/bin
PATH: /opt/panda3d/bin
PATH: /opt/perl-5.24.1/bin
PATH: /opt/pngprogs-1.6.30/bin
PATH: /opt/qemu-3.1.0_SDL/bin
PATH: /opt/rust-1.36.0/bin
PATH: /opt/ruby-2.5.2/bin
PATH: /opt/samba-4.8.1/bin
PATH: /opt/sound-studio/bin
PATH: /opt/tcl-8.6.9/bin
PATH: /opt/tiffprogs-4.0.8/bin
PATH: /opt/wine-5.5/bin
PATH: /opt/wine-5.0/bin
PATH: /opt/xboinc_client-7.14.2/bin


Expand All @@ -82,7 +71,7 @@ configure:1938: found /usr/bin/gcc
configure:1949: result: gcc
configure:2178: checking for C compiler version
configure:2187: gcc --version >&5
gcc (GCC) 8.3.0
gcc (GCC) 8.2.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Expand All @@ -91,11 +80,11 @@ configure:2198: $? = 0
configure:2187: gcc -v >&5
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/i486-pc-linux-gnu/8.3.0/lto-wrapper
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/i486-pc-linux-gnu/8.2.0/lto-wrapper
Target: i486-pc-linux-gnu
Configured with: ../gcc-8.3.0-src/configure --enable-languages=c,c++,go --disable-nls --disable-multilib --prefix=/usr --sysconfdir=/etc --includedir=/usr/include --localstatedir=/var --mandir=/usr/share/man --infodir=/usr/share/info --host=i486-pc-linux-gnu --build=i486-pc-linux-gnu --target=i486-pc-linux-gnu
Configured with: ../gcc-8.2.0-src/configure --enable-languages=c,c++,go --disable-nls --disable-multilib --prefix=/usr --sysconfdir=/etc --includedir=/usr/include --localstatedir=/var --mandir=/usr/share/man --infodir=/usr/share/info --host=i486-pc-linux-gnu --build=i486-pc-linux-gnu --target=i486-pc-linux-gnu
Thread model: posix
gcc version 8.3.0 (GCC)
gcc version 8.2.0 (GCC)
configure:2198: $? = 0
configure:2187: gcc -V >&5
gcc: error: unrecognized command line option '-V'
Expand Down Expand Up @@ -267,10 +256,10 @@ generated by GNU Autoconf 2.69. Invocation command line was
CONFIG_COMMANDS =
$ ./config.status

on DellM6400
on lifebook3

config.status:725: creating Makefile
configure:4776: === configuring in libUseful-4 (/home/colum/work/term_wifi/libUseful-4)
configure:4776: === configuring in libUseful-4 (/home/colum/term_wifi/libUseful-4)
configure:4839: running /bin/sh ./configure --disable-option-checking '--prefix=/usr/local' --cache-file=/dev/null --srcdir=.

## ---------------- ##
Expand Down
2 changes: 1 addition & 1 deletion config.status
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ Copyright (C) 2012 Free Software Foundation, Inc.
This config.status script is free software; the Free Software Foundation
gives unlimited permission to copy, distribute and modify it."

ac_pwd='/home/colum/work/term_wifi'
ac_pwd='/home/colum/term_wifi'
srcdir='.'
test -n "$AWK" || AWK=awk
# The default lists apply if the user does not specify any file.
Expand Down
15 changes: 7 additions & 8 deletions libUseful-4/Encodings.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ int EncodingParse(const char *Str)
if (strcmp(Str,"base64")==0) return(ENCODE_BASE64);
if (strcmp(Str,"i64")==0) return(ENCODE_IBASE64);
if (strcmp(Str,"p64")==0) return(ENCODE_PBASE64);
if (strcmp(Str,"r64")==0) return(ENCODE_RBASE64);
if (strcmp(Str,"rfc4648")==0) return(ENCODE_RBASE64);
if (strncmp(Str,"xx",2)==0) return(ENCODE_XXENC);
if (strncmp(Str,"uu",2)==0) return(ENCODE_UUENC);
if (strcmp(Str,"crypt")==0) return(ENCODE_CRYPT);
if (strcmp(Str,"z85")==0) return(ENCODE_Z85);

return(ENCODE_NONE);
}
Expand Down Expand Up @@ -82,48 +85,44 @@ char *EncodeBytes(char *Buffer, const char *Bytes, int len, int Encoding)
RetStr=SetStrLen(RetStr,len * 4);
to64frombits((unsigned char *) RetStr,(unsigned char *) Bytes,len);
break;
break;

case ENCODE_IBASE64:
RetStr=SetStrLen(RetStr,len * 4);
Radix64frombits((unsigned char *) RetStr,(unsigned char *) Bytes,len,IBASE64_CHARS,'\0');
break;
break;

case ENCODE_PBASE64:
RetStr=SetStrLen(RetStr,len * 4);
Radix64frombits((unsigned char *) RetStr,(unsigned char *) Bytes,len,PBASE64_CHARS,'\0');
break;
break;

case ENCODE_RBASE64:
RetStr=SetStrLen(RetStr,len * 4);
Radix64frombits((unsigned char *) RetStr,(unsigned char *) Bytes,len,RBASE64_CHARS,'=');
break;

case ENCODE_CRYPT:
RetStr=SetStrLen(RetStr,len * 4);
Radix64frombits((unsigned char *) RetStr,(unsigned char *) Bytes,len,CRYPT_CHARS,'\0');
break;
break;

case ENCODE_XXENC:
RetStr=SetStrLen(RetStr,len * 4);
Radix64frombits((unsigned char *) RetStr,(unsigned char *) Bytes,len,XXENC_CHARS,'+');
break;
break;

case ENCODE_UUENC:
RetStr=SetStrLen(RetStr,len * 4);
Radix64frombits((unsigned char *) RetStr,(unsigned char *) Bytes,len,UUENC_CHARS,'\'');
break;
break;

case ENCODE_ASCII85:
RetStr=Ascii85(RetStr,Bytes,len,ASCII85_CHARS);
break;
break;

case ENCODE_Z85:
RetStr=Ascii85(RetStr,Bytes,len,Z85_CHARS);
break;
break;

case ENCODE_OCTAL:
for (i=0; i < len; i++)
Expand Down
22 changes: 22 additions & 0 deletions libUseful-4/Encodings.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ If you *KNOW* that your output of DecodeBytes is going to be null-terminated tex
#define ENCODE_XXENC 67
#define ENCODE_UUENC 68
#define ENCODE_CRYPT 69
#define ENCODE_RBASE64 70

#define ENCODE_ASCII85 85
#define ENCODE_Z85 86
Expand All @@ -77,6 +78,7 @@ If you *KNOW* that your output of DecodeBytes is going to be null-terminated tex
#define BASE64_CHARS "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
#define IBASE64_CHARS "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789+/"
#define PBASE64_CHARS "0123456789-ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"
#define RBASE64_CHARS "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_" //RFC4648 compliant
#define CRYPT_CHARS "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
#define UUENC_CHARS " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"
#define XXENC_CHARS "+-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
Expand All @@ -89,6 +91,26 @@ If you *KNOW* that your output of DecodeBytes is going to be null-terminated tex
extern "C" {
#endif

//parse a string that describes an encoding. Strings are:
//"8" Octal Encoding
//"oct" Octal Encoding
//"10" Decimal Encoding
//"dec" Decimal Encoding
//"16" HexaDecimal Encoding
//"hex" HexaDecimal Encoding
//"64" base64 Encoding
//"b64" base64 Encoding
//"r64" rfc4648 compliant alternative base64 Encoding
//"rfc4648" rfc4648 compliant alternative base64 Encoding
//"i64" alternative base64 Encoding
//"p64" another alternative base64 Encoding
//"xx" xxencode encoding
//"uu" uuencode encoding
//"crypt" unix 'crypt' encoding
//"ascii85" ascii85 encoding
//"z86" z85 encoding


int EncodingParse(const char *Str);

char *EncodeBytes(char *Buffer, const char *Bytes, int len, int Encoding);
Expand Down
2 changes: 1 addition & 1 deletion libUseful-4/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CC = gcc
VERSION = 4.27
VERSION = 4.29
CFLAGS = -g -O2
LDFLAGS=
LIBS = -lc -lc -lc -lc -lc -lc -lc -lc
Expand Down
2 changes: 1 addition & 1 deletion libUseful-4/Makefile.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CC = @CC@
VERSION = 4.27
VERSION = 4.29
CFLAGS = @CFLAGS@ @SIMD_CFLAGS@
LDFLAGS=@LDFLAGS@
LIBS = @LIBS@
Expand Down
1 change: 1 addition & 0 deletions libUseful-4/OpenSSL.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ int DoSSLClientNegotiation(STREAM *S, int Flags);
//'Flags' can be any of the LU_SSL_ flags listed above
int DoSSLServerNegotiation(STREAM *S, int Flags);

//This is called automatically by STREAMClose. You won't generally explicitly call this.
void OpenSSLClose(STREAM *S);

//call this before doing anything else with a STREAM that's been 'accept'-ed from a server socket. If the stream is encrypted
Expand Down
33 changes: 27 additions & 6 deletions libUseful-4/Stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ STREAM *STREAMOpen(const char *URL, const char *Config)
if (ptr) ptr++;
else ptr=URL;

Proto=CopyStr(Proto,"file");
Proto=CopyStr(Proto,"");
ParseURL(ptr, &Proto, &Host, &Token, &User, &Pass, &Path, &Args);
if (StrValid(Token)) Port=strtoul(Token,NULL,10);

Expand All @@ -981,22 +981,43 @@ STREAM *STREAMOpen(const char *URL, const char *Config)
{
case 'c':
if (strcasecmp(Proto,"cmd")==0) S=STREAMSpawnCommand(URL+4, Config);
else S=STREAMFileOpen(URL, Flags);
break;

case 'f':
if (strcasecmp(Proto,"file")==0)
{
ptr=URL+5;

//file protocol can have 3 '/' after file, like this file:///myfile.txt. So we strip off two of these
//thus anything with 3 of them is a full path from /, anything with less than that is a relative path
//from the current directory
if (*ptr=='/') ptr++;
if (*ptr=='/') ptr++;
S=STREAMFileOpen(ptr, Flags);
}
else S=STREAMFileOpen(URL, Flags);
break;

case 'h':
if (
(strcmp(Proto,"http")==0) ||
(strcmp(Proto,"https")==0)
) S=HTTPWithConfig(URL, Config);
(strcasecmp(Proto,"http")==0) ||
(strcasecmp(Proto,"https")==0)
)
{
S=HTTPWithConfig(URL, Config);
//the 'write only' and 'read only' flags normally result in one or another
//buffer not being allocated (as it's not expected to be needed). However
//with HTTP 'write' means 'POST', and we still need both read and write
//buffers to read from and to the server, so we must unset these flags
Flags &= ~(SF_WRONLY | SF_RDONLY);
}
else S=STREAMFileOpen(URL, Flags);
break;

case 'm':
if (strcmp(Proto,"mmap")==0) S=STREAMFileOpen(URL+5, Flags | SF_MMAP);
if (strcasecmp(Proto,"mmap")==0) S=STREAMFileOpen(URL+5, Flags | SF_MMAP);
else S=STREAMFileOpen(URL, Flags);
break;

case 't':
Expand All @@ -1012,7 +1033,7 @@ STREAM *STREAMOpen(const char *URL, const char *Config)
S->Type=STREAM_TYPE_TTY;
}
}
else
else
{
S=STREAMCreate();
S->Path=CopyStr(S->Path,URL);
Expand Down
3 changes: 3 additions & 0 deletions libUseful-4/Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ S=STREAMOpen("/tmp/myfile.txt", "w");
The first argument can be any of the following types:
/tmp/myfile.txt file
file:///tmp/myfile.txt file, web-browser style. Note 3 '/' symbols.
mmap:/tmp/myfile.txt memory mapped file
tty:/dev/ttyS0:38400 open a serial device, in this case at 38400 baud
udp:192.168.2.1:53 udp network connection
Expand All @@ -32,6 +33,8 @@ https:www.google.com https network connection
cmd:cat /etc/hosts run command 'cat /etc/hosts' and read/write to/from it
ssh:192.168.2.1:1022/cat /etc/hosts ssh connect, running the command 'cat /etc/hosts'
'file://' is provided for compatiblity with web-browser environments. In this url format the protocol part is 'file://'. If a third '/' is present, like so 'file:///etc/services' then the url is a full path from the filesystem root. Any lesser number of '/' indicates a relative path from the current directory
in the case of SSH stream the default action, if no 'config' flags are passed, is to run a command. 'x' config flag will also explictly run a command. 'r' will cat a file from the remote server. 'w' will cat from the stream TO a file on the remote server.
S=STREAMOpen("ssh:192.168.2.1/myfile.txt", "r"); //read from 'myfile.txt' in current directory
Expand Down
2 changes: 1 addition & 1 deletion libUseful-4/Terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1822,7 +1822,7 @@ char *TerminalReadText(char *RetStr, int Flags, STREAM *S)
if (Flags & TERM_SHOWTEXTSTARS) STREAMWriteString("\x08*",S);

//ensure we don't return NULL, but that we instead return an empty string
RetStr=CatStr(RetStr, "");
if (RetStr==NULL) RetStr=CatStr(RetStr, "");

break;
}
Expand Down
Loading

0 comments on commit 54441b8

Please sign in to comment.