Skip to content

Commit cc83fc3

Browse files
committed
Coverity: String not null terminated
1. Swap out strdup() for a malloc() and memcpy(). Then nul terminate the string before tokenizing. Fixes CID: 572834
1 parent 8c0c7fd commit cc83fc3

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/ssh.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1658,9 +1658,13 @@ static int DoSshPubKey(const byte* in, word32 inSz, byte** out,
16581658
/*
16591659
SSH format is:
16601660
type AAAABASE64ENCODEDKEYDATA comment
1661+
1662+
allocate a copy to tokenize, add a null terminator.
16611663
*/
1662-
c = WSTRDUP((const char*)in, heap, DYNTYPE_STRING);
1664+
c = (char*)WMALLOC(inSz + 1, heap, DYNTYPE_STRING);
16631665
if (c != NULL) {
1666+
WMEMCPY(c, in, inSz);
1667+
c[inSz-1] = 0;
16641668
type = WSTRTOK(c, " \n", &last);
16651669
key = WSTRTOK(NULL, " \n", &last);
16661670
}

0 commit comments

Comments
 (0)