mirror of
https://github.com/cathugger/mkp224o.git
synced 2025-01-09 11:07:19 -03:00
harden pseudo-YAML validation
This commit is contained in:
parent
ee0257dc88
commit
91f484cbc7
3 changed files with 7 additions and 4 deletions
|
@ -419,4 +419,4 @@ test_ed25519.c.o: ed25519/ed25519-donna/ed25519-donna-64bit-tables.h
|
||||||
test_ed25519.c.o: ed25519/ed25519-donna/ed25519-donna-64bit-x86.h
|
test_ed25519.c.o: ed25519/ed25519-donna/ed25519-donna-64bit-x86.h
|
||||||
test_ed25519.c.o: ed25519/ed25519-donna/ed25519-donna-impl-base.h
|
test_ed25519.c.o: ed25519/ed25519-donna/ed25519-donna-impl-base.h
|
||||||
vec.c.o: vec.h
|
vec.c.o: vec.h
|
||||||
yaml.c.o: types.h yaml.h ioutil.h base64.h common.h
|
yaml.c.o: types.h yaml.h ioutil.h base32.h base64.h common.h
|
||||||
|
|
2
base32.h
2
base32.h
|
@ -4,7 +4,7 @@ char *base32_to(char *dst,const u8 *src,size_t slen);
|
||||||
#define BASE32_TO_LEN(l) (((l) * 8 + 4) / 5)
|
#define BASE32_TO_LEN(l) (((l) * 8 + 4) / 5)
|
||||||
// converts src string from base32
|
// converts src string from base32
|
||||||
size_t base32_from(u8 *dst,u8 *dmask,const char *src);
|
size_t base32_from(u8 *dst,u8 *dmask,const char *src);
|
||||||
// calculates length needed to store data converted from base
|
// calculates length needed to store data converted from base32
|
||||||
#define BASE32_FROM_LEN(l) (((l) * 5 + 7) / 8)
|
#define BASE32_FROM_LEN(l) (((l) * 5 + 7) / 8)
|
||||||
// validates base32 string and optionally stores length of valid data
|
// validates base32 string and optionally stores length of valid data
|
||||||
// returns 1 if whole string is good, 0 if string contains invalid data
|
// returns 1 if whole string is good, 0 if string contains invalid data
|
||||||
|
|
7
yaml.c
7
yaml.c
|
@ -10,6 +10,7 @@
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "yaml.h"
|
#include "yaml.h"
|
||||||
#include "ioutil.h"
|
#include "ioutil.h"
|
||||||
|
#include "base32.h"
|
||||||
#include "base64.h"
|
#include "base64.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
|
@ -122,7 +123,7 @@ void yamlout_writekeys(const char *hostname,const u8 *formated_public,const u8 *
|
||||||
int yamlin_parseandcreate(FILE *fin,char *sname,const char *hostname)
|
int yamlin_parseandcreate(FILE *fin,char *sname,const char *hostname)
|
||||||
{
|
{
|
||||||
char line[256];
|
char line[256];
|
||||||
size_t len;
|
size_t len,cnt;
|
||||||
u8 pubbuf[FORMATTED_PUBLIC_LEN];
|
u8 pubbuf[FORMATTED_PUBLIC_LEN];
|
||||||
u8 secbuf[FORMATTED_SECRET_LEN];
|
u8 secbuf[FORMATTED_SECRET_LEN];
|
||||||
int hashost = 0,haspub = 0,hassec = 0,skipthis = 0;
|
int hashost = 0,haspub = 0,hassec = 0,skipthis = 0;
|
||||||
|
@ -198,7 +199,9 @@ int yamlin_parseandcreate(FILE *fin,char *sname,const char *hostname)
|
||||||
len = strlen(p);
|
len = strlen(p);
|
||||||
switch (keyt) {
|
switch (keyt) {
|
||||||
case HOST:
|
case HOST:
|
||||||
if (len != ONION_LEN) {
|
if (len != ONION_LEN || base32_valid(p,&cnt) || cnt != BASE32_TO_LEN(PUBONION_LEN) ||
|
||||||
|
strcmp(&p[cnt],&hostname_example[cnt]) != 0)
|
||||||
|
{
|
||||||
fprintf(stderr,"ERROR: invalid hostname syntax\n");
|
fprintf(stderr,"ERROR: invalid hostname syntax\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue