mirror of
https://github.com/cathugger/mkp224o.git
synced 2025-01-09 19:17:19 -03:00
prevent possible buffer overflow
This commit is contained in:
parent
8f1e08973d
commit
cf5ac5f929
2 changed files with 13 additions and 9 deletions
2
base64.h
2
base64.h
|
@ -9,3 +9,5 @@ size_t base64_from(u8 *dst,const char *src,size_t slen);
|
||||||
// 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
|
||||||
int base64_valid(const char *src,size_t *count);
|
int base64_valid(const char *src,size_t *count);
|
||||||
|
// aligns data length to something base64 can represent without padding
|
||||||
|
#define BASE64_DATA_ALIGN(l) (((l + 2) / 3) * 3)
|
||||||
|
|
20
yaml.c
20
yaml.c
|
@ -131,8 +131,8 @@ int yamlin_parseandcreate(FILE *fin,char *sname,const char *hostname)
|
||||||
{
|
{
|
||||||
char line[256];
|
char line[256];
|
||||||
size_t len,cnt;
|
size_t len,cnt;
|
||||||
u8 pubbuf[FORMATTED_PUBLIC_LEN];
|
u8 pubbuf[BASE64_DATA_ALIGN(FORMATTED_PUBLIC_LEN)];
|
||||||
u8 secbuf[FORMATTED_SECRET_LEN];
|
u8 secbuf[BASE64_DATA_ALIGN(FORMATTED_SECRET_LEN)];
|
||||||
int hashost = 0,haspub = 0,hassec = 0,skipthis = 0;
|
int hashost = 0,haspub = 0,hassec = 0,skipthis = 0;
|
||||||
enum keytype { HOST, PUB, SEC } keyt;
|
enum keytype { HOST, PUB, SEC } keyt;
|
||||||
|
|
||||||
|
@ -219,19 +219,21 @@ int yamlin_parseandcreate(FILE *fin,char *sname,const char *hostname)
|
||||||
skipthis = 1;
|
skipthis = 1;
|
||||||
break;
|
break;
|
||||||
case PUB:
|
case PUB:
|
||||||
if (len != PUBKEY_LEN || !base64_valid(p,0)) {
|
if (len != PUBKEY_LEN || !base64_valid(p,0) ||
|
||||||
|
base64_from(pubbuf,p,len) != FORMATTED_PUBLIC_LEN)
|
||||||
|
{
|
||||||
fprintf(stderr,"ERROR: invalid pubkey syntax\n");
|
fprintf(stderr,"ERROR: invalid pubkey syntax\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
base64_from(pubbuf,p,len);
|
|
||||||
haspub = 1;
|
haspub = 1;
|
||||||
break;
|
break;
|
||||||
case SEC:
|
case SEC:
|
||||||
if (len != SECKEY_LEN || !base64_valid(p,0)) {
|
if (len != SECKEY_LEN || !base64_valid(p,0) ||
|
||||||
|
base64_from(secbuf,p,len) != FORMATTED_SECRET_LEN)
|
||||||
|
{
|
||||||
fprintf(stderr,"ERROR: invalid seckey syntax\n");
|
fprintf(stderr,"ERROR: invalid seckey syntax\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
base64_from(secbuf,p,len);
|
|
||||||
hassec = 1;
|
hassec = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -273,16 +275,16 @@ int yamlin_parseandcreate(FILE *fin,char *sname,const char *hostname)
|
||||||
skipthis = 1;
|
skipthis = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!feof(fin)) {
|
if (!feof(fin)) {
|
||||||
fprintf(stderr,"error while reading input\n");
|
fprintf(stderr,"error while reading input\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hostname) {
|
if (hostname) {
|
||||||
fprintf(stderr,"hostname wasn't found in input\n");
|
fprintf(stderr,"hostname wasn't found in input\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue