diff options
author | Andreas Schneider <asn@cryptomilk.org> | 2018-07-05 13:21:23 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2018-07-05 13:21:23 +0200 |
commit | c3dac948c916c1330419980f71a72c253efd19b8 (patch) | |
tree | f278a86a4e5b85038bafb85cf67e4b5eff921401 /src/pki.c | |
parent | c866768da48be13a98cf55f58cc1aebae31e0bdd (diff) | |
download | libssh-c3dac948c916c1330419980f71a72c253efd19b8.tar.gz libssh-c3dac948c916c1330419980f71a72c253efd19b8.tar.xz libssh-c3dac948c916c1330419980f71a72c253efd19b8.zip |
pki: Improve pubkey buffer handling form file
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'src/pki.c')
-rw-r--r-- | src/pki.c | 21 |
1 files changed, 16 insertions, 5 deletions
@@ -1028,6 +1028,7 @@ int ssh_pki_import_pubkey_file(const char *filename, ssh_key *pkey) enum ssh_keytypes_e type; struct stat sb; char *key_buf, *p; + size_t buflen, i; const char *q; FILE *file; off_t size; @@ -1079,19 +1080,29 @@ int ssh_pki_import_pubkey_file(const char *filename, ssh_key *pkey) return SSH_ERROR; } key_buf[size] = '\0'; + buflen = strlen(key_buf); q = p = key_buf; - while (*p != '\0' && !isspace((int)*p)) p++; - *p = '\0'; + for (i = 0; i < buflen; i++) { + if (isspace((int)p[i])) { + p[i] = '\0'; + break; + } + } type = ssh_key_type_from_name(q); if (type == SSH_KEYTYPE_UNKNOWN) { SAFE_FREE(key_buf); return SSH_ERROR; } - q = ++p; - while (*p != '\0' && !isspace((int)*p)) p++; - *p = '\0'; + + q = &p[i + 1]; + for (; i < buflen; i++) { + if (isspace((int)p[i])) { + p[i] = '\0'; + break; + } + } rc = ssh_pki_import_pubkey_base64(q, type, pkey); SAFE_FREE(key_buf); |