Avoid potential memory leak.
[sgt/putty] / puttygen.c
index 072b7d0..add9431 100644 (file)
@@ -22,6 +22,23 @@ static int requested_help;
 
 static char *cmdline_keyfile = NULL;
 
+/*
+ * Print a modal (Really Bad) message box and perform a fatal exit.
+ */
+void modalfatalbox(char *fmt, ...)
+{
+    va_list ap;
+    char *stuff;
+
+    va_start(ap, fmt);
+    stuff = dupvprintf(fmt, ap);
+    va_end(ap);
+    MessageBox(NULL, stuff, "PuTTYgen Fatal Error",
+              MB_SYSTEMMODAL | MB_ICONERROR | MB_OK);
+    sfree(stuff);
+    exit(1);
+}
+
 /* ----------------------------------------------------------------------
  * Progress report code. This is really horrible :-)
  */
@@ -206,14 +223,6 @@ static int prompt_keyfile(HWND hwnd, char *dlgtitle,
 }
 
 /*
- * This function is needed to link with the DES code. We need not
- * have it do anything at all.
- */
-void logevent(char *msg)
-{
-}
-
-/*
  * Dialog-box function for the Licence box.
  */
 static int CALLBACK LicenceProc(HWND hwnd, UINT msg,
@@ -356,10 +365,8 @@ static void setupbigedit1(HWND hwnd, int id, int idstatic, struct RSAKey *key)
 
     dec1 = bignum_decimal(key->exponent);
     dec2 = bignum_decimal(key->modulus);
-    buffer = smalloc(strlen(dec1) + strlen(dec2) +
-                    strlen(key->comment) + 30);
-    sprintf(buffer, "%d %s %s %s",
-           bignum_bitcount(key->modulus), dec1, dec2, key->comment);
+    buffer = dupprintf("%d %s %s %s", bignum_bitcount(key->modulus),
+                      dec1, dec2, key->comment);
     SetDlgItemText(hwnd, id, buffer);
     SetDlgItemText(hwnd, idstatic,
                   "&Public key for pasting into authorized_keys file:");
@@ -1146,12 +1153,13 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
                    int ret;
                    FILE *fp = fopen(filename, "r");
                    if (fp) {
-                       char buffer[FILENAME_MAX + 80];
+                       char *buffer;
                        fclose(fp);
-                       sprintf(buffer, "Overwrite existing file\n%.*s?",
-                               FILENAME_MAX, filename);
+                       buffer = dupprintf("Overwrite existing file\n%s?",
+                                          filename);
                        ret = MessageBox(hwnd, buffer, "PuTTYgen Warning",
                                         MB_YESNO | MB_ICONWARNING);
+                       sfree(buffer);
                        if (ret != IDYES)
                            break;
                    }
@@ -1189,12 +1197,13 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
                    int ret;
                    FILE *fp = fopen(filename, "r");
                    if (fp) {
-                       char buffer[FILENAME_MAX + 80];
+                       char *buffer;
                        fclose(fp);
-                       sprintf(buffer, "Overwrite existing file\n%.*s?",
-                               FILENAME_MAX, filename);
+                       buffer = dupprintf("Overwrite existing file\n%s?",
+                                          filename);
                        ret = MessageBox(hwnd, buffer, "PuTTYgen Warning",
                                         MB_YESNO | MB_ICONWARNING);
+                       sfree(buffer);
                        if (ret != IDYES)
                            break;
                    }
@@ -1384,7 +1393,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
     int argc;
     char **argv;
 
-    split_into_argv(cmdline, &argc, &argv);
+    split_into_argv(cmdline, &argc, &argv, NULL);
 
     if (argc > 0) {
        /*