1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-07-31 00:03:07 +03:00

examples: Avoid buffer overrun

and provide helpful warning message

CID 1533680:  Memory - illegal accesses  (OVERRUN)

Thanks coverity

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Jakub Jelen
2024-01-26 15:06:17 +01:00
parent a8b7e17aa0
commit 5dd42dfa22

View File

@ -531,6 +531,14 @@ static int auth_publickey(ssh_session session,
}
}
if (i >= AUTH_KEYS_MAX_LINE_SIZE) {
fprintf(stderr,
"warning: The line %d in %s too long! Skipping.\n",
lineno,
authorizedkeys);
continue;
}
if (p[i] == '#' || p[i] == '\0' || p[i] == '\n') {
continue;
}
@ -545,7 +553,16 @@ static int auth_publickey(ssh_session session,
type = ssh_key_type_from_name(q);
q = &p[i + 1];
i++;
if (i >= AUTH_KEYS_MAX_LINE_SIZE) {
fprintf(stderr,
"warning: The line %d in %s too long! Skipping.\n",
lineno,
authorizedkeys);
continue;
}
q = &p[i];
for (; i < AUTH_KEYS_MAX_LINE_SIZE; i++) {
if (isspace((int)p[i])) {
p[i] = '\0';