Fix zero-rows-cols-crash
[u/mdw/putty] / import.c
index b6d32cb..6c936ff 100644 (file)
--- a/import.c
+++ b/import.c
 #include "ssh.h"
 #include "misc.h"
 
-#define PUT_32BIT(cp, value) do { \
-  (cp)[3] = (unsigned char)(value); \
-  (cp)[2] = (unsigned char)((value) >> 8); \
-  (cp)[1] = (unsigned char)((value) >> 16); \
-  (cp)[0] = (unsigned char)((value) >> 24); } while (0)
-
-#define GET_32BIT(cp) \
-    (((unsigned long)(unsigned char)(cp)[0] << 24) | \
-    ((unsigned long)(unsigned char)(cp)[1] << 16) | \
-    ((unsigned long)(unsigned char)(cp)[2] << 8) | \
-    ((unsigned long)(unsigned char)(cp)[3]))
-
 int openssh_encrypted(const Filename *filename);
 struct ssh2_userkey *openssh_read(const Filename *filename, char *passphrase,
                                  const char **errmsg_p);
@@ -56,7 +44,7 @@ int import_possible(int type)
 int import_target_type(int type)
 {
     /*
-     * There are no known foreign SSH1 key formats.
+     * There are no known foreign SSH-1 key formats.
      */
     return SSH_KEYTYPE_SSH2;
 }
@@ -78,7 +66,7 @@ int import_encrypted(const Filename *filename, int type, char **comment)
 }
 
 /*
- * Import an SSH1 key.
+ * Import an SSH-1 key.
  */
 int import_ssh1(const Filename *filename, int type,
                struct RSAKey *key, char *passphrase, const char **errmsg_p)
@@ -87,7 +75,7 @@ int import_ssh1(const Filename *filename, int type,
 }
 
 /*
- * Import an SSH2 key.
+ * Import an SSH-2 key.
  */
 struct ssh2_userkey *import_ssh2(const Filename *filename, int type,
                                 char *passphrase, const char **errmsg_p)
@@ -100,7 +88,7 @@ struct ssh2_userkey *import_ssh2(const Filename *filename, int type,
 }
 
 /*
- * Export an SSH1 key.
+ * Export an SSH-1 key.
  */
 int export_ssh1(const Filename *filename, int type, struct RSAKey *key,
                char *passphrase)
@@ -109,7 +97,7 @@ int export_ssh1(const Filename *filename, int type, struct RSAKey *key,
 }
 
 /*
- * Export an SSH2 key.
+ * Export an SSH-2 key.
  */
 int export_ssh2(const Filename *filename, int type,
                 struct ssh2_userkey *key, char *passphrase)
@@ -456,7 +444,7 @@ static struct openssh_key *load_openssh_key(const Filename *filename,
             memset(ret->keyblob, 0, ret->keyblob_size);
             sfree(ret->keyblob);
         }
-        memset(&ret, 0, sizeof(ret));
+        memset(ret, 0, sizeof(*ret));
        sfree(ret);
     }
     if (errmsg_p) *errmsg_p = errmsg;
@@ -473,7 +461,7 @@ int openssh_encrypted(const Filename *filename)
     ret = key->encrypted;
     memset(key->keyblob, 0, key->keyblob_size);
     sfree(key->keyblob);
-    memset(&key, 0, sizeof(key));
+    memset(key, 0, sizeof(*key));
     sfree(key);
     return ret;
 }
@@ -666,7 +654,7 @@ struct ssh2_userkey *openssh_read(const Filename *filename, char *passphrase,
     }
     memset(key->keyblob, 0, key->keyblob_size);
     sfree(key->keyblob);
-    memset(&key, 0, sizeof(key));
+    memset(key, 0, sizeof(*key));
     sfree(key);
     if (errmsg_p) *errmsg_p = errmsg;
     return retval;
@@ -778,6 +766,7 @@ int openssh_write(const Filename *filename, struct ssh2_userkey *key,
         footer = "-----END DSA PRIVATE KEY-----\n";
     } else {
         assert(0);                     /* zoinks! */
+       exit(1); /* XXX: GCC doesn't understand assert() on some systems. */
     }
 
     /*
@@ -918,9 +907,9 @@ int openssh_write(const Filename *filename, struct ssh2_userkey *key,
  */
 
 /*
- * The format of the base64 blob is largely ssh2-packet-formatted,
+ * The format of the base64 blob is largely SSH-2-packet-formatted,
  * except that mpints are a bit different: they're more like the
- * old ssh1 mpint. You have a 32-bit bit count N, followed by
+ * old SSH-1 mpint. You have a 32-bit bit count N, followed by
  * (N+7)/8 bytes of data.
  * 
  * So. The blob contains:
@@ -932,7 +921,7 @@ int openssh_write(const Filename *filename, struct ssh2_userkey *key,
  *  - string encrypted-blob
  * 
  * (The first size field includes the size field itself and the
- * magic number before it. All other size fields are ordinary ssh2
+ * magic number before it. All other size fields are ordinary SSH-2
  * strings, so the size field indicates how much data is to
  * _follow_.)
  * 
@@ -977,7 +966,7 @@ int openssh_write(const Filename *filename, struct ssh2_userkey *key,
  * `dl-modp{sign{dsa' prefixes.
  * 
  * Finally, the encryption. The cipher-type string appears to be
- * either `none' or `3des-cbc'. Looks as if this is SSH2-style
+ * either `none' or `3des-cbc'. Looks as if this is SSH-2-style
  * 3des-cbc (i.e. outer cbc rather than inner). The key is created
  * from the passphrase by means of yet another hashing faff:
  * 
@@ -1110,7 +1099,7 @@ static struct sshcom_key *load_sshcom_key(const Filename *filename,
             memset(ret->keyblob, 0, ret->keyblob_size);
             sfree(ret->keyblob);
         }
-        memset(&ret, 0, sizeof(ret));
+        memset(ret, 0, sizeof(*ret));
        sfree(ret);
     }
     if (errmsg_p) *errmsg_p = errmsg;
@@ -1152,7 +1141,7 @@ int sshcom_encrypted(const Filename *filename, char **comment)
     *comment = dupstr(key->comment);
     memset(key->keyblob, 0, key->keyblob_size);
     sfree(key->keyblob);
-    memset(&key, 0, sizeof(key));
+    memset(key, 0, sizeof(*key));
     sfree(key);
     return answer;
 }
@@ -1427,7 +1416,7 @@ struct ssh2_userkey *sshcom_read(const Filename *filename, char *passphrase,
     }
     memset(key->keyblob, 0, key->keyblob_size);
     sfree(key->keyblob);
-    memset(&key, 0, sizeof(key));
+    memset(key, 0, sizeof(*key));
     sfree(key);
     if (errmsg_p) *errmsg_p = errmsg;
     return ret;
@@ -1509,6 +1498,7 @@ int sshcom_write(const Filename *filename, struct ssh2_userkey *key,
        type = "dl-modp{sign{dsa-nist-sha1},dh{plain}}";
     } else {
         assert(0);                     /* zoinks! */
+       exit(1); /* XXX: GCC doesn't understand assert() on some systems. */
     }
 
     /*