sanity check on the end of the buffer in example

pull/361/head
JacobBarthelmeh 2021-08-27 13:41:41 -06:00
parent 7968cb479e
commit df753b0b4b
1 changed files with 6 additions and 1 deletions

View File

@ -1335,6 +1335,7 @@ static int LoadPublicKeyBuffer(byte* buf, word32 bufSz, PwMapList* list)
{
char* str = (char*)buf;
char* delimiter;
char* end = (char*)buf + bufSz;
byte* publicKey64;
word32 publicKey64Sz;
byte* username;
@ -1351,12 +1352,14 @@ static int LoadPublicKeyBuffer(byte* buf, word32 bufSz, PwMapList* list)
if (buf == NULL || bufSz == 0)
return 0;
while (*str != 0) {
while (str < end && *str != 0) {
/* Skip the public key type. This example will always be ssh-rsa. */
delimiter = strchr(str, ' ');
if (delimiter == NULL) {
return -1;
}
if (str >= end)
break;
str = delimiter + 1;
delimiter = strchr(str, ' ');
if (delimiter == NULL) {
@ -1365,6 +1368,8 @@ static int LoadPublicKeyBuffer(byte* buf, word32 bufSz, PwMapList* list)
publicKey64 = (byte*)str;
*delimiter = 0;
publicKey64Sz = (word32)(delimiter - str);
if (str >= end)
break;
str = delimiter + 1;
delimiter = strchr(str, '\n');
if (delimiter == NULL) {