]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Fix an assortment of dupprintf() format string bugs.
authorSimon Tatham <anakin@pobox.com>
Sun, 17 Nov 2013 14:05:44 +0000 (14:05 +0000)
committerSimon Tatham <anakin@pobox.com>
Sun, 17 Nov 2013 14:05:44 +0000 (14:05 +0000)
I've enabled gcc's format-string checking on dupprintf, by declaring
it in misc.h to have the appropriate GNU-specific attribute. This
pointed out a selection of warnings, which I've fixed.

[originally from svn r10084]

cmdline.c
misc.h
ssh.c
unix/gtkwin.c
unix/uxplink.c
unix/uxpty.c

index a4c91601079e1b461007fe22a03edf08dfcaa3d5..bafb939914af4ca0ea24165e40d104fcadff2bd1 100644 (file)
--- a/cmdline.c
+++ b/cmdline.c
@@ -275,7 +275,7 @@ int cmdline_process_param(char *p, char *value, int need_save, Conf *conf)
                return ret;
            }
 
-           key = dupprintf("%c%.*s", type, q - value, value);
+           key = dupprintf("%c%.*s", type, (int)(q - value), value);
            val = dupstr(q+1);
        } else {
             /*
@@ -307,7 +307,7 @@ int cmdline_process_param(char *p, char *value, int need_save, Conf *conf)
            return ret;
        }
 
-       host = dupprintf("%.*s", portp - value, value);
+       host = dupprintf("%.*s", (int)(portp - value), value);
        conf_set_str(conf, CONF_ssh_nc_host, host);
        conf_set_int(conf, CONF_ssh_nc_port, atoi(portp + 1));
         sfree(host);
diff --git a/misc.h b/misc.h
index eff4a5e1eafb1b80208d3203a794136ee2becd5e..aa761999b7a396c7539643398911a363cd2a366d 100644 (file)
--- a/misc.h
+++ b/misc.h
@@ -26,7 +26,11 @@ char ctrlparse(char *s, char **next);
 
 char *dupstr(const char *s);
 char *dupcat(const char *s1, ...);
-char *dupprintf(const char *fmt, ...);
+char *dupprintf(const char *fmt, ...)
+#ifdef __GNUC__
+    __attribute__ ((format (printf, 1, 2)))
+#endif
+    ;
 char *dupvprintf(const char *fmt, va_list ap);
 void burnstr(char *string);
 
diff --git a/ssh.c b/ssh.c
index 25a2e24b91c6e82832d281dd3088b5b7fb6acb8e..0f318075a697fb55223d49ad622decf63fb85ab5 100644 (file)
--- a/ssh.c
+++ b/ssh.c
@@ -3292,7 +3292,7 @@ static void ssh_socket_log(Plug plug, int type, SockAddr addr, int port,
             if (sk_addr_needs_port(addr)) {
                 msg = dupprintf("Connecting to %s port %d", addrbuf, port);
             } else {
-                msg = dupprintf("Connecting to %s", addrbuf, port);
+                msg = dupprintf("Connecting to %s", addrbuf);
             }
         } else {
             msg = dupprintf("Failed to connect to %s: %s", addrbuf, error_msg);
@@ -5292,7 +5292,7 @@ static void ssh1_msg_port_open(Ssh ssh, struct Packet *pktin)
     ssh_pkt_getstring(pktin, &host, &hostsize);
     port = ssh_pkt_getuint32(pktin);
 
-    pf.dhost = dupprintf(".*s", hostsize, host);
+    pf.dhost = dupprintf("%.*s", hostsize, host);
     pf.dport = port;
     pfp = find234(ssh->rportfwds, &pf, NULL);
 
index 88ce8b5505d4dfb5349c984447376e94d8e2baa7..812e4faf99041f62acb3b6dd003a5872ac116a9b 100644 (file)
@@ -2901,7 +2901,7 @@ char *setup_fonts_ucs(struct gui_data *inst)
             for (i = 0; i < 2; i++)
                 if (fonts[i])
                     unifont_destroy(fonts[i]);
-            return dupprintf("%s: unable to load wide font \"%s\"", fs->name);
+            return dupprintf("unable to load wide font \"%s\"", fs->name);
        }
     } else {
        fonts[2] = NULL;
@@ -2917,8 +2917,7 @@ char *setup_fonts_ucs(struct gui_data *inst)
             for (i = 0; i < 3; i++)
                 if (fonts[i])
                     unifont_destroy(fonts[i]);
-           return dupprintf("%s: unable to load wide bold font \"%s\"",
-                             fs->name);
+           return dupprintf("unable to load wide bold font \"%s\"", fs->name);
        }
     }
 
index 81356d363fd07ff4a30f1717f203759b6cdfaf8d..7fbaa36a80d260589f799a74c8bd5de92f3cbf0a 100644 (file)
@@ -204,7 +204,7 @@ static char *get_ttychar(struct termios *t, int index)
     cc_t c = t->c_cc[index];
 #if defined(_POSIX_VDISABLE)
     if (c == _POSIX_VDISABLE)
-       return dupprintf("");
+       return dupstr("");
 #endif
     return dupprintf("^<%d>", c);
 }
index 98f917932b5561856d9ef99f843aa36a6555a38b..54ba082c3a0e6a74107a1e923c2ff1001d9a418f 100644 (file)
@@ -938,7 +938,7 @@ static const char *pty_init(void *frontend, void **backend_handle, Conf *conf,
 
     *backend_handle = pty;
 
-    *realhost = dupprintf("\0");
+    *realhost = dupstr("");
 
     return NULL;
 }