-/* $OpenBSD: ssh-keygen.c,v 1.161 2007/09/09 11:38:01 sobrado Exp $ */
+/* $OpenBSD: ssh-keygen.c,v 1.163 2007/10/02 17:49:58 chl Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
fprintf(stderr, "%s (%s): ", prompt, identity_file);
if (fgets(buf, sizeof(buf), stdin) == NULL)
exit(1);
- if (strchr(buf, '\n'))
- *strchr(buf, '\n') = 0;
+ buf[strcspn(buf, "\n")] = '\0';
if (strcmp(buf, "") != 0)
strlcpy(identity_file, buf, sizeof(identity_file));
have_identity = 1;
f = fopen(identity_file, "r");
if (f != NULL) {
while (fgets(line, sizeof(line), f)) {
- i = strlen(line) - 1;
- if (line[i] != '\n') {
+ if ((cp = strchr(line, '\n')) == NULL) {
error("line %d too long: %.40s...", num, line);
skip = 1;
continue;
skip = 0;
continue;
}
- line[i] = '\0';
+ *cp = '\0';
/* Skip leading whitespace, empty and comment lines. */
for (cp = line; *cp == ' ' || *cp == '\t'; cp++)
Key *public;
char *cp, *cp2, *kp, *kp2;
char line[16*1024], tmp[MAXPATHLEN], old[MAXPATHLEN];
- int c, i, skip = 0, inplace = 0, num = 0, invalid = 0, has_unhashed = 0;
+ int c, skip = 0, inplace = 0, num = 1, invalid = 0, has_unhashed = 0;
if (!have_identity) {
cp = tilde_expand_filename(_PATH_SSH_USER_HOSTFILE, pw->pw_uid);
}
while (fgets(line, sizeof(line), in)) {
- num++;
- i = strlen(line) - 1;
- if (line[i] != '\n') {
+ if ((cp = strchr(line, '\n')) == NULL) {
error("line %d too long: %.40s...", num, line);
skip = 1;
invalid = 1;
continue;
}
+ num++;
if (skip) {
skip = 0;
continue;
}
- line[i] = '\0';
+ *cp = '\0';
/* Skip leading whitespace, empty and comment lines. */
for (cp = line; *cp == ' ' || *cp == '\t'; cp++)
key_free(private);
exit(1);
}
- if (strchr(new_comment, '\n'))
- *strchr(new_comment, '\n') = 0;
+ new_comment[strcspn(new_comment, "\n")] = '\0';
}
/* Save the file using the new passphrase. */