Bugzilla – Attachment 1861 Details for
Bug 1783
ssh-keygen -L and -l give misleading error messages when fopen() fails
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
fatal() with a useful message if fopen() fails
ssh-keygen-check-fopen.diff (text/plain), 3.87 KB, created by
Iain Morgan
on 2010-06-16 03:57:18 AEST
(
hide
)
Description:
fatal() with a useful message if fopen() fails
Filename:
MIME Type:
Creator:
Iain Morgan
Created:
2010-06-16 03:57:18 AEST
Size:
3.87 KB
patch
obsolete
>Index: ssh-keygen.c >=================================================================== >RCS file: /cvs/openssh/ssh-keygen.c,v >retrieving revision 1.204 >diff -u -r1.204 ssh-keygen.c >--- ssh-keygen.c 21 May 2010 04:58:32 -0000 1.204 >+++ ssh-keygen.c 8 Jun 2010 21:33:13 -0000 >@@ -561,65 +561,66 @@ > comment = NULL; > } > >- f = fopen(identity_file, "r"); >- if (f != NULL) { >- while (fgets(line, sizeof(line), f)) { >- if ((cp = strchr(line, '\n')) == NULL) { >- error("line %d too long: %.40s...", >- num + 1, line); >- skip = 1; >- continue; >- } >- num++; >- if (skip) { >- skip = 0; >- continue; >- } >- *cp = '\0'; >+ if ((f = fopen(identity_file, "r")) == NULL) >+ fatal("%s: %s", identity_file, strerror(errno)); > >- /* Skip leading whitespace, empty and comment lines. */ >- for (cp = line; *cp == ' ' || *cp == '\t'; cp++) >- ; >- if (!*cp || *cp == '\n' || *cp == '#') >- continue; >- i = strtol(cp, &ep, 10); >- if (i == 0 || ep == NULL || (*ep != ' ' && *ep != '\t')) { >- int quoted = 0; >- comment = cp; >- for (; *cp && (quoted || (*cp != ' ' && >- *cp != '\t')); cp++) { >- if (*cp == '\\' && cp[1] == '"') >- cp++; /* Skip both */ >- else if (*cp == '"') >- quoted = !quoted; >- } >- if (!*cp) >- continue; >- *cp++ = '\0'; >+ while (fgets(line, sizeof(line), f)) { >+ if ((cp = strchr(line, '\n')) == NULL) { >+ error("line %d too long: %.40s...", >+ num + 1, line); >+ skip = 1; >+ continue; >+ } >+ num++; >+ if (skip) { >+ skip = 0; >+ continue; >+ } >+ *cp = '\0'; >+ >+ /* Skip leading whitespace, empty and comment lines. */ >+ for (cp = line; *cp == ' ' || *cp == '\t'; cp++) >+ ; >+ if (!*cp || *cp == '\n' || *cp == '#') >+ continue; >+ i = strtol(cp, &ep, 10); >+ if (i == 0 || ep == NULL || (*ep != ' ' && *ep != '\t')) { >+ int quoted = 0; >+ comment = cp; >+ for (; *cp && (quoted || (*cp != ' ' && >+ *cp != '\t')); cp++) { >+ if (*cp == '\\' && cp[1] == '"') >+ cp++; /* Skip both */ >+ else if (*cp == '"') >+ quoted = !quoted; > } >- ep = cp; >- public = key_new(KEY_RSA1); >+ if (!*cp) >+ continue; >+ *cp++ = '\0'; >+ } >+ ep = cp; >+ public = key_new(KEY_RSA1); >+ if (key_read(public, &cp) != 1) { >+ cp = ep; >+ key_free(public); >+ public = key_new(KEY_UNSPEC); > if (key_read(public, &cp) != 1) { >- cp = ep; > key_free(public); >- public = key_new(KEY_UNSPEC); >- if (key_read(public, &cp) != 1) { >- key_free(public); >- continue; >- } >+ continue; > } >- comment = *cp ? cp : comment; >- fp = key_fingerprint(public, fptype, rep); >- ra = key_fingerprint(public, SSH_FP_MD5, SSH_FP_RANDOMART); >- printf("%u %s %s (%s)\n", key_size(public), fp, >- comment ? comment : "no comment", key_type(public)); >- if (log_level >= SYSLOG_LEVEL_VERBOSE) >- printf("%s\n", ra); >- xfree(ra); >- xfree(fp); >- key_free(public); >- invalid = 0; > } >+ comment = *cp ? cp : comment; >+ fp = key_fingerprint(public, fptype, rep); >+ ra = key_fingerprint(public, SSH_FP_MD5, SSH_FP_RANDOMART); >+ printf("%u %s %s (%s)\n", key_size(public), fp, >+ comment ? comment : "no comment", key_type(public)); >+ if (log_level >= SYSLOG_LEVEL_VERBOSE) >+ printf("%s\n", ra); >+ xfree(ra); >+ xfree(fp); >+ key_free(public); >+ invalid = 0; >+ > fclose(f); > } > if (invalid) { >@@ -1418,15 +1419,17 @@ > struct stat st; > char *key_fp, *ca_fp; > Buffer options, option; >+ FILE *f; > u_char *name, *data; > u_int i, dlen, v00; > > if (!have_identity) > ask_filename(pw, "Enter file in which the key is"); >- if (stat(identity_file, &st) < 0) { >- perror(identity_file); >- exit(1); >- } >+ if ((f = fopen(identity_file, "r")) == NULL) >+ fatal("%s: %s", identity_file, strerror(errno)); >+ fclose(f); >+ >+ if ((key = key_load_public(identity_file, NULL)) == NULL) > if ((key = key_load_public(identity_file, NULL)) == NULL) > fatal("%s is not a public key", identity_file); > if (!key_is_cert(key))
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 1783
: 1861 |
1864