nmh-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nmh-commits] nmh uip/scansbr.c uip/whatnowsbr.c ChangeLog [nmh-1_3-bran


From: Peter Maydell
Subject: [Nmh-commits] nmh uip/scansbr.c uip/whatnowsbr.c ChangeLog [nmh-1_3-branch]
Date: Thu, 22 May 2008 10:42:10 +0000

CVSROOT:        /sources/nmh
Module name:    nmh
Branch:         nmh-1_3-branch
Changes by:     Peter Maydell <pm215>   08/05/22 10:42:10

Modified files:
        uip            : scansbr.c whatnowsbr.c 
        .              : ChangeLog 

Log message:
        Don't use MB_CUR_MAX if compiling without multibyte support.
        Don't rely on return value of sprintf(). (Ported from trunk.)

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/nmh/uip/scansbr.c?cvsroot=nmh&only_with_tag=nmh-1_3-branch&r1=1.11&r2=1.11.2.1
http://cvs.savannah.gnu.org/viewcvs/nmh/uip/whatnowsbr.c?cvsroot=nmh&only_with_tag=nmh-1_3-branch&r1=1.9&r2=1.9.2.1
http://cvs.savannah.gnu.org/viewcvs/nmh/ChangeLog?cvsroot=nmh&only_with_tag=nmh-1_3-branch&r1=1.254.2.10&r2=1.254.2.11

Patches:
Index: uip/scansbr.c
===================================================================
RCS file: /sources/nmh/nmh/uip/scansbr.c,v
retrieving revision 1.11
retrieving revision 1.11.2.1
diff -u -b -r1.11 -r1.11.2.1
--- uip/scansbr.c       13 Apr 2007 11:53:08 -0000      1.11
+++ uip/scansbr.c       22 May 2008 10:42:09 -0000      1.11.2.1
@@ -2,7 +2,7 @@
 /*
  * scansbr.c -- routines to help scan along...
  *
- * $Id: scansbr.c,v 1.11 2007/04/13 11:53:08 jjr Exp $
+ * $Id: scansbr.c,v 1.11.2.1 2008/05/22 10:42:09 pm215 Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -68,6 +68,11 @@
 int sc_width (void);                   /* from termsbr.c */
 static int mh_fputs(char *, FILE *);
 
+#ifdef MULTIBYTE_SUPPORT
+#define SCAN_CHARWIDTH MB_CUR_MAX
+#else
+#define SCAN_CHARWIDTH 1
+#endif
 
 int
 scan (FILE *inb, int innum, int outnum, char *nfs, int width, int curflg,
@@ -98,7 +103,7 @@
                width = MAXSCANL;
        }
        dat[3] = slwidth = width;
-       scanl = (char *) mh_xmalloc((size_t) MB_CUR_MAX * (slwidth + 2) );
+       scanl = (char *) mh_xmalloc((size_t) SCAN_CHARWIDTH * (slwidth + 2) );
        if (outnum)
            umask(~m_gmprot());
 

Index: uip/whatnowsbr.c
===================================================================
RCS file: /sources/nmh/nmh/uip/whatnowsbr.c,v
retrieving revision 1.9
retrieving revision 1.9.2.1
diff -u -b -r1.9 -r1.9.2.1
--- uip/whatnowsbr.c    21 Feb 2006 03:58:31 -0000      1.9
+++ uip/whatnowsbr.c    22 May 2008 10:42:10 -0000      1.9.2.1
@@ -2,7 +2,7 @@
 /*
  * whatnowsbr.c -- the WhatNow shell
  *
- * $Id: whatnowsbr.c,v 1.9 2006/02/21 03:58:31 levine Exp $
+ * $Id: whatnowsbr.c,v 1.9.2.1 2008/05/22 10:42:10 pm215 Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -120,6 +120,7 @@
 static int check_draft (char *);
 static int whomfile (char **, char *);
 static int removefile (char *);
+static void writelscmd(char *, int, char *, char **);
 
 #ifdef HAVE_LSTAT
 static int copyf (char *, char *);
@@ -353,17 +354,7 @@
             *  Use the user's shell so that we can take advantage of any
             *  syntax that the user is accustomed to.
             */
-
-           cp = buf + sprintf(buf, "$SHELL -c \" cd %s;ls", cwd);
-
-           while (*++argp != (char *)0) {
-               if (cp + strlen(*argp) + 2 >= buf + BUFSIZ)
-                   adios((char *)0, "arguments too long");
-
-               cp += sprintf(cp, " %s", *argp);
-           }
-
-           (void)strcat(cp, "\"");
+           writelscmd(buf, sizeof(buf), cwd, argp);
            (void)system(buf);
            break;
 
@@ -423,17 +414,7 @@
             *  Build a command line that causes the user's shell to list the 
file name
             *  arguments.  This handles and wildcard expansion, tilde 
expansion, etc.
             */
-
-           cp = buf + sprintf(buf, "$SHELL -c \" cd %s;ls", cwd);
-
-           while (*++argp != (char *)0) {
-               if (cp + strlen(*argp) + 3 >= buf + BUFSIZ)
-                   adios((char *)0, "arguments too long");
-
-               cp += sprintf(cp, " %s", *argp);
-           }
-
-           (void)strcat(cp, "\"");
+           writelscmd(buf, sizeof(buf), cwd, argp);
 
            /*
             *  Read back the response from the shell, which contains a number 
of lines
@@ -560,6 +541,40 @@
     /*NOTREACHED*/
 }
 
+
+/*
+ * Build a command line that causes the user's shell to list the file name
+ * arguments.  This handles and wildcard expansion, tilde expansion, etc.
+ */
+static void
+writelscmd(char *buf, int bufsz, char *cwd, char **argp)
+{
+    char *cp;
+    int ln = snprintf(buf, bufsz, "$SHELL -c \" cd %s;ls", cwd);
+    /* NB that some snprintf() return -1 on overflow rather than the
+     * new C99 mandated 'number of chars that would have been written'
+     */
+    /* length checks here and inside the loop allow for the
+     * trailing " and NUL
+     */
+    if (ln < 0 || ln + 2 > bufsz)
+       adios((char *)0, "arguments too long");
+    
+    cp = buf + ln;
+    
+    while (*++argp != (char *)0) {
+       ln = strlen(*argp);
+       /* +3 for leading space and trailing quote and NUL */
+       if (ln + 3 > bufsz - (cp-buf))
+           adios((char *)0, "arguments too long");
+       *cp++ = ' ';
+       memcpy(cp, *argp, ln+1);
+       cp += ln;
+    }
+    *cp++ = '"';
+    *cp = 0;
+}
+
 /*
  * EDIT
  */

Index: ChangeLog
===================================================================
RCS file: /sources/nmh/nmh/ChangeLog,v
retrieving revision 1.254.2.10
retrieving revision 1.254.2.11
diff -u -b -r1.254.2.10 -r1.254.2.11
--- ChangeLog   21 May 2008 18:07:29 -0000      1.254.2.10
+++ ChangeLog   22 May 2008 10:42:10 -0000      1.254.2.11
@@ -1,3 +1,14 @@
+2008-05-22  Peter Maydell  <address@hidden>
+
+       * uip/scansbr.c: don't use MB_CUR_MAX if we aren't compiled
+       with multibyte support. (Ported from trunk.)
+
+       * uip/whatnowsbr.c: factor out common code for writing ls
+       shell command, and make it do more sensible buffer length
+       checks. Also avoid relying on the return value of sprintf(),
+       as some old systems don't return number of characters written.
+       (Ported from trunk.)
+
 2008-05-21  Peter Maydell  <address@hidden>
 
        * sbr/utils.c (mh_xrealloc): don't assume realloc() can




reply via email to

[Prev in Thread] Current Thread [Next in Thread]