]> diplodocus.org Git - nmh/commitdiff
Silence more gcc format-string warnings.
authorRalph Corderoy <ralph@inputplus.co.uk>
Wed, 9 Aug 2017 14:42:48 +0000 (15:42 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Wed, 9 Aug 2017 14:42:48 +0000 (15:42 +0100)
By enabling more checks, gcc has found some real bugs, e.g. `printf(buf,
"%d", i)'.  Other changes required duplicating the formatting call with
a constant format string;  a local macro was used to avoid repeating all
the many arguments.

sbr/ext_hook.c
sbr/message_id.c
sbr/oauth.c
uip/annosbr.c
uip/fmtdump.c
uip/mhlogin.c
uip/sendsbr.c

index d29c046..63869e5 100644 (file)
@@ -50,7 +50,7 @@ ext_hook(char *hook_name, char *message_file_name_1, char *message_file_name_2)
        if (did_message == 0) {
            char *msghook;
            if ((msghook = context_find("msg-hook")) != NULL)
-               inform(msghook);
+                inform("%s", msghook);
            else {
                char errbuf[BUFSIZ];
                snprintf(errbuf, sizeof(errbuf), "external hook \"%s\"", hook);
index aaaab32..a66d876 100644 (file)
@@ -38,18 +38,19 @@ char *
 message_id (time_t tclock, int content_id) {
   switch (message_id_style) {
     case NMH_MESSAGE_ID_LOCALNAME: {
-      char *format = content_id  ?  "<%d.%ld.%%d@%s>"  :  "<%d.%ld@%s>";
-
-      snprintf (message_id_, sizeof message_id_, format,
-                (int) getpid (), (long) tclock, LocalName (1));
-
+#define P(fmt) \
+    snprintf(message_id_, sizeof message_id_, \
+        (fmt), (int)getpid(), (long)tclock, LocalName(1))
+
+            if (content_id)
+                P("<%d.%ld.%%d@%s>");
+            else
+                P("<%d.%ld@%s>");
+#undef P
       break;
     }
 
     case NMH_MESSAGE_ID_RANDOM: {
-      char *format = content_id
-        ?  "<%d-%ld.%06ld%%d@%.*s.%.*s.%.*s>"
-        :  "<%d-%ld.%06ld@%.*s.%.*s.%.*s>";
       /* Use a sequence of digits divisible by 3 because that will
          expand to base64 without any waste.  Must be shorter than 58,
          see below. */
@@ -95,11 +96,18 @@ message_id (time_t tclock, int content_id) {
         /* The format string inserts a couple of dots, for the benefit
            of spam filters that want to see a message id with a final
            part that resembles a hostname. */
-        snprintf (message_id_, sizeof message_id_, format,
-                  getpid (), (long) now.tv_sec, (long) now.tv_usec,
-                  one_third, rnd_base64,
-                  one_third, &rnd_base64[one_third],
-                  one_third, &rnd_base64[2*one_third]);
+#define P(fmt) \
+    snprintf(message_id_, sizeof message_id_, (fmt), \
+        getpid(), (long)now.tv_sec, (long)now.tv_usec, \
+        (int)one_third, rnd_base64, \
+        (int)one_third, &rnd_base64[one_third], \
+        (int)one_third, &rnd_base64[2*one_third])
+
+            if (content_id)
+                P("<%d-%ld.%06ld%%d@%.*s.%.*s.%.*s>");
+            else
+                P("<%d-%ld.%06ld@%.*s.%.*s.%.*s>");
+#undef P
       }
 
       break;
index 76ff879..89288c1 100755 (executable)
@@ -140,7 +140,8 @@ mh_oauth_do_xoauth(const char *user, const char *svc, unsigned char **oauth_res,
     FILE *fp;
     char *client_res;
 
-    if (!mh_oauth_new (&ctx, svc)) adios(NULL, mh_oauth_get_err_string(ctx));
+    if (!mh_oauth_new (&ctx, svc))
+        adios(NULL, "%s", mh_oauth_get_err_string(ctx));
 
     if (log != NULL) mh_oauth_log_to(stderr, ctx);
 
@@ -157,7 +158,7 @@ mh_oauth_do_xoauth(const char *user, const char *svc, unsigned char **oauth_res,
     }
 
     if ((cred = mh_oauth_cred_load(fp, ctx, user)) == NULL) {
-        adios(NULL, mh_oauth_get_err_string(ctx));
+        adios(NULL, "%s", mh_oauth_get_err_string(ctx));
     }
 
     if (!mh_oauth_access_token_valid(time(NULL), cred)) {
@@ -169,12 +170,12 @@ mh_oauth_do_xoauth(const char *user, const char *svc, unsigned char **oauth_res,
                 adios(NULL, "credentials rejected -- run mhlogin -saslmech xoauth2 -authservice %s", svc);
             }
             inform("error refreshing OAuth2 token");
-            adios(NULL, mh_oauth_get_err_string(ctx));
+            adios(NULL, "%s", mh_oauth_get_err_string(ctx));
         }
 
         fseek(fp, 0, SEEK_SET);
         if (!mh_oauth_cred_save(fp, cred, user)) {
-            adios(NULL, mh_oauth_get_err_string(ctx));
+            adios(NULL, "%s", mh_oauth_get_err_string(ctx));
         }
     }
 
index 2c1ce75..cf5ea55 100644 (file)
@@ -52,7 +52,7 @@ annotate (char *file, char *comp, char *text, int inplace, int datesw, int delet
     }
 
     if (stat(file, &s) == -1) {
-       advise("can't get access and modification times for %s", file);
+        inform("can't get access and modification times for %s", file);
        preserve_actime_and_modtime = 0;
     }
 
@@ -62,7 +62,7 @@ annotate (char *file, char *comp, char *text, int inplace, int datesw, int delet
     i = annosbr (fd, file, comp, text, inplace, datesw, delete, append);
 
     if (preserve_actime_and_modtime && utime(file, &b) == -1)
-       advise("can't set access and modification times for %s", file);
+        inform("can't set access and modification times for %s", file);
 
     lkclosedata (fd, file);
     return i;
index 6a6ef7c..55d7dcc 100644 (file)
@@ -439,7 +439,7 @@ f_typestr(int t)
        case FT_V_MATCH: return("V_MATCH");
        case FT_V_AMATCH: return("V_AMATCH");
        default:
-               printf(buf, "/* ??? #%d */", t);
+                snprintf(buf, sizeof buf, "/* ??? #%d */", t);
                return(buf);
        }
 }
@@ -457,7 +457,7 @@ c_typestr(int t)
 
        buf[0] = '\0';
        if (t & ~(CT_ADDR|CT_DATE))
-               printf(buf, "0x%x ", t);
+                snprintf(buf, sizeof buf, "0x%x ", t);
        strcat(buf, "<");
        i = 0;
        FNORD(CT_ADDR, "ADDR");
@@ -474,7 +474,7 @@ c_flagsstr(int t)
 
        buf[0] = '\0';
        if (t & ~(CF_TRUE|CF_PARSED|CF_DATEFAB|CF_TRIMMED))
-               printf(buf, "0x%x ", t);
+                snprintf(buf, sizeof buf, "0x%x ", t);
        strcat(buf, "<");
        i = 0;
        FNORD(CF_TRUE, "TRUE");
index 1cc1c23..3e10f99 100644 (file)
@@ -64,7 +64,7 @@ do_login(const char *svc, const char *user, const char *browser, int snoop)
     }
 
     if (!mh_oauth_new(&ctx, svc)) {
-        adios(NULL, mh_oauth_get_err_string(ctx));
+        adios(NULL, "%s", mh_oauth_get_err_string(ctx));
     }
 
     if (snoop) {
@@ -74,7 +74,7 @@ do_login(const char *svc, const char *user, const char *browser, int snoop)
     fn = mh_xstrdup(mh_oauth_cred_fn(svc));
 
     if ((url = mh_oauth_get_authorize_url(ctx)) == NULL) {
-      adios(NULL, mh_oauth_get_err_string(ctx));
+      adios(NULL, "%s", mh_oauth_get_err_string(ctx));
     }
 
     if (browser) {
@@ -110,7 +110,7 @@ do_login(const char *svc, const char *user, const char *browser, int snoop)
     }
     if (cred == NULL) {
       inform("error exchanging code for OAuth2 token");
-      adios(NULL, mh_oauth_get_err_string(ctx));
+      adios(NULL, "%s", mh_oauth_get_err_string(ctx));
     }
 
     cred_file = lkfopendata(fn, "r+", &failed_to_lock);
@@ -121,7 +121,7 @@ do_login(const char *svc, const char *user, const char *browser, int snoop)
       adios(fn, "oops");
     }
     if (!mh_oauth_cred_save(cred_file, cred, user)) {
-      adios(NULL, mh_oauth_get_err_string(ctx));
+      adios(NULL, "%s", mh_oauth_get_err_string(ctx));
     }
     if (lkfclosedata(cred_file, fn) != 0) {
       adios (fn, "oops");
index 2d4d0a8..7d54f43 100644 (file)
@@ -135,7 +135,7 @@ sendsbr (char **vec, int vecp, char *program, char *draft, struct stat *st,
 #ifdef OAUTH_SUPPORT
                const char *errmsg;
                if (setup_oauth_params(vec, nvecsp, auth_svc, &errmsg) != OK) {
-                       adios(NULL, errmsg);
+                        adios(NULL, "%s", errmsg);
                }
 #else
                 adios(NULL, "send built without OAUTH_SUPPORT, "
@@ -751,7 +751,7 @@ handle_sendfrom(char **vec, int *vecp, char *draft, const char *auth_svc) {
 
     /* Extract address and host from From: header line in draft. */
     if (get_from_header_info(draft, &addr, &host, &message) != OK) {
-        adios(draft, message);
+        adios(draft, "%s", message);
     }
 
     /* Merge in any address or host specific switches to post(1) from profile. */
@@ -768,7 +768,7 @@ handle_sendfrom(char **vec, int *vecp, char *draft, const char *auth_svc) {
             if (strcmp(*vp, "xoauth2") == 0) {
 #ifdef OAUTH_SUPPORT
                 if (setup_oauth_params(vec, vecp, auth_svc, &message) != OK) {
-                    adios(NULL, message);
+                    adios(NULL, "%s", message);
                 }
                 break;
 #else