]> andersk Git - openssh.git/blobdiff - ssh-keygen.c
- tdeval@cvs.openbsd.org 2004/11/24 18:10:42
[openssh.git] / ssh-keygen.c
index ed3cdb3ed8f174c602e9bab5693ee28a14744f20..657937629b1d7ab87842a508248884d9b7e0bb75 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh-keygen.c,v 1.159 2007/01/12 20:20:41 jmc 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
@@ -141,8 +141,7 @@ ask_filename(struct passwd *pw, const char *prompt)
        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;
@@ -241,7 +240,7 @@ do_convert_private_ssh2_from_blob(u_char *blob, u_int blen)
        buffer_init(&b);
        buffer_append(&b, blob, blen);
 
-       magic  = buffer_get_int(&b);
+       magic = buffer_get_int(&b);
        if (magic != SSH_COM_PRIVATE_KEY_MAGIC) {
                error("bad magic 0x%x != 0x%x", magic, SSH_COM_PRIVATE_KEY_MAGIC);
                buffer_free(&b);
@@ -284,7 +283,7 @@ do_convert_private_ssh2_from_blob(u_char *blob, u_int blen)
                buffer_get_bignum_bits(&b, key->dsa->priv_key);
                break;
        case KEY_RSA:
-               e  = buffer_get_char(&b);
+               e = buffer_get_char(&b);
                debug("e %lx", e);
                if (e < 30) {
                        e <<= 8;
@@ -536,8 +535,7 @@ do_fingerprint(struct passwd *pw)
        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;
@@ -547,7 +545,7 @@ do_fingerprint(struct passwd *pw)
                                skip = 0;
                                continue;
                        }
-                       line[i] = '\0';
+                       *cp = '\0';
 
                        /* Skip leading whitespace, empty and comment lines. */
                        for (cp = line; *cp == ' ' || *cp == '\t'; cp++)
@@ -615,7 +613,7 @@ do_known_hosts(struct passwd *pw, const char *name)
        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);
@@ -650,19 +648,18 @@ do_known_hosts(struct passwd *pw, const char *name)
        }
 
        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++)
@@ -962,8 +959,7 @@ do_change_comment(struct passwd *pw)
                        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. */
@@ -1006,7 +1002,7 @@ do_change_comment(struct passwd *pw)
 static void
 usage(void)
 {
-       fprintf(stderr, "Usage: %s [options]\n", __progname);
+       fprintf(stderr, "usage: %s [options]\n", __progname);
        fprintf(stderr, "Options:\n");
        fprintf(stderr, "  -a trials   Number of trials for screening DH-GEX moduli.\n");
        fprintf(stderr, "  -B          Show bubblebabble digest of key file.\n");
This page took 0.038175 seconds and 4 git commands to generate.