On Tue, Jan 06, 2015 at 01:42:49AM -0500, Brian Callahan wrote:
> Hi Scarlett --
> 
> I don't have time to do more than eyeball this right now, but I just
> want to make two quick comments:
> 1. Usually we use CVS to send patches. Lets you send a single file
> instead of a whole tarball :-)
> But that aside...
> 2. Could you put all this nice information into the patches themselves?
> Partly for attribution, partly to see quickly what each patch is doing
> and why, and partly because it makes it easier to track future bug fixes
> from those same sources.
> 
> ~Brian
>

Thanks for your quick response, Brian. I've added descriptions to the top
of each patch.


Index: w3m/Makefile
===================================================================
RCS file: /cvs/ports/www/w3m/Makefile,v
retrieving revision 1.84
diff -u -p -u -r1.84 Makefile
--- w3m/Makefile        16 Jul 2014 08:20:01 -0000      1.84
+++ w3m/Makefile        6 Jan 2015 09:16:56 -0000
@@ -51,6 +51,9 @@ CONFIGURE_ARGS+=--enable-m17n=ISO-8859-1
 DOCSRC=                ${WRKSRC}/doc
 .endif
 
+post-patch:
+       @cp ${FILESDIR}/alloc.h ${WRKSRC}
+
 post-install:
        ${INSTALL_DATA_DIR} ${PREFIX}/share/doc/w3m
        cd ${DOCSRC}; \
Index: w3m/files/alloc.h
===================================================================
RCS file: w3m/files/alloc.h
diff -N w3m/files/alloc.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ w3m/files/alloc.h   6 Jan 2015 09:16:56 -0000
@@ -0,0 +1,39 @@
+/*
+ * by Scarlett. public domain.
+ * replacements for w3m's allocation macros which add overflow
+ * detection and concentrate the macros in one file
+ */
+#ifndef W3_ALLOC_H
+#define W3_ALLOC_H
+#include <gc.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <limits.h>
+
+static inline size_t
+z_mult_no_oflow_(size_t n, size_t size)
+{
+       if (size != 0 && n > SIZE_MAX / size) {
+               fprintf(stderr,
+                   "w3m: overflow in malloc, %zu*%zu\n", n, size);
+               exit(1);
+       }
+       return n * size;
+}
+
+#define New(type) \
+       (GC_MALLOC(sizeof(type)))
+
+#define NewAtom(type) \
+       (GC_MALLOC_ATOMIC(sizeof(type)))
+
+#define New_N(type, n) \
+       (GC_MALLOC(z_mult_no_oflow_((n), sizeof(type))))
+
+#define NewAtom_N(type, n) \
+       (GC_MALLOC_ATOMIC(z_mult_no_oflow_((n), sizeof(type))))
+
+#define New_Reuse(type, ptr, n) \
+       (GC_REALLOC((ptr), z_mult_no_oflow_((n), sizeof(type))))
+
+#endif /* W3_ALLOC_H */
Index: w3m/patches/patch-Str_c
===================================================================
RCS file: w3m/patches/patch-Str_c
diff -N w3m/patches/patch-Str_c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ w3m/patches/patch-Str_c     6 Jan 2015 09:16:56 -0000
@@ -0,0 +1,127 @@
+Use asprintf() instead of rolling our own printf string length detection.
+
+--- Str.c.orig Mon Jan  5 22:49:07 2015
++++ Str.c      Mon Jan  5 22:52:59 2015
+@@ -427,103 +427,27 @@
+ Str
+ Sprintf(char *fmt, ...)
+ {
+-    int len = 0;
+-    int status = SP_NORMAL;
+-    int p = 0;
+-    char *f;
+-    Str s;
+-    va_list ap;
++      Str s;
++      char *cb;
++      int ret;
++      size_t n;
++      va_list ap;
+ 
+-    va_start(ap, fmt);
+-    for (f = fmt; *f; f++) {
+-      redo:
+-      switch (status) {
+-      case SP_NORMAL:
+-          if (*f == '%') {
+-              status = SP_PREC;
+-              p = 0;
+-          }
+-          else
+-              len++;
+-          break;
+-      case SP_PREC:
+-          if (IS_ALPHA(*f)) {
+-              /* conversion char. */
+-              double vd;
+-              int vi;
+-              char *vs;
+-              void *vp;
+-
+-              switch (*f) {
+-              case 'l':
+-              case 'h':
+-              case 'L':
+-              case 'w':
+-                  continue;
+-              case 'd':
+-              case 'i':
+-              case 'o':
+-              case 'x':
+-              case 'X':
+-              case 'u':
+-                  vi = va_arg(ap, int);
+-                  len += (p > 0) ? p : 10;
+-                  break;
+-              case 'f':
+-              case 'g':
+-              case 'e':
+-              case 'G':
+-              case 'E':
+-                  vd = va_arg(ap, double);
+-                  len += (p > 0) ? p : 15;
+-                  break;
+-              case 'c':
+-                  len += 1;
+-                  vi = va_arg(ap, int);
+-                  break;
+-              case 's':
+-                  vs = va_arg(ap, char *);
+-                  vi = strlen(vs);
+-                  len += (p > vi) ? p : vi;
+-                  break;
+-              case 'p':
+-                  vp = va_arg(ap, void *);
+-                  len += 10;
+-                  break;
+-              case 'n':
+-                  vp = va_arg(ap, void *);
+-                  break;
+-              }
+-              status = SP_NORMAL;
+-          }
+-          else if (IS_DIGIT(*f))
+-              p = p * 10 + *f - '0';
+-          else if (*f == '.')
+-              status = SP_PREC2;
+-          else if (*f == '%') {
+-              status = SP_NORMAL;
+-              len++;
+-          }
+-          break;
+-      case SP_PREC2:
+-          if (IS_ALPHA(*f)) {
+-              status = SP_PREC;
+-              goto redo;
+-          }
+-          break;
++      va_start(ap, fmt);
++      ret = vasprintf(&cb, fmt, ap);
++      if (ret == -1) {
++              fprintf(stderr,
++                  "Sprintf: vasprintf failed\n");
++              exit(1);
+       }
+-    }
+-    va_end(ap);
+-    s = Strnew_size(len * 2);
+-    va_start(ap, fmt);
+-    vsprintf(s->ptr, fmt, ap);
+-    va_end(ap);
+-    s->length = strlen(s->ptr);
+-    if (s->length > len * 2) {
+-      fprintf(stderr, "Sprintf: string too long\n");
+-      exit(1);
+-    }
+-    return s;
++      va_end(ap);
++
++      n = (size_t) ret + 1;
++      s = Strnew_size(n);
++      s->length = ret;
++      memcpy(s->ptr, cb, n);
++      free(cb);
++      return s;
+ }
+ 
+ Str
Index: w3m/patches/patch-cookie_c
===================================================================
RCS file: w3m/patches/patch-cookie_c
diff -N w3m/patches/patch-cookie_c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ w3m/patches/patch-cookie_c  6 Jan 2015 09:16:56 -0000
@@ -0,0 +1,27 @@
+Pass the char pointer in the string struct to printf %s instead of
+the string struct itself.
+Print time_t using %lld instead of %ld to allow for 64-bit time_t
+
+--- cookie.c.orig      Mon Jan  5 22:28:06 2015
++++ cookie.c   Mon Jan  5 22:43:18 2015
+@@ -247,7 +247,7 @@
+               Strcat(tmp, Sprintf("; $Domain=\"%s\"", p1->domain->ptr));
+           if (p1->portl)
+               Strcat(tmp,
+-                     Sprintf("; $Port=\"%s\"", portlist2str(p1->portl)));
++                     Sprintf("; $Port=\"%s\"", portlist2str(p1->portl)->ptr));
+       }
+     }
+     return tmp;
+@@ -461,9 +461,9 @@
+     for (p = First_cookie; p; p = p->next) {
+       if (!(p->flag & COO_USE) || p->flag & COO_DISCARD)
+           continue;
+-      fprintf(fp, "%s\t%s\t%s\t%ld\t%s\t%s\t%d\t%d\t%s\t%s\t%s\n",
++      fprintf(fp, "%s\t%s\t%s\t%lld\t%s\t%s\t%d\t%d\t%s\t%s\t%s\n",
+               parsedURL2Str(&p->url)->ptr,
+-              p->name->ptr, p->value->ptr, p->expires,
++              p->name->ptr, p->value->ptr, (long long) p->expires,
+               p->domain->ptr, p->path->ptr, p->flag,
+               p->version, str2charp(p->comment),
+               (p->portl) ? portlist2str(p->portl)->ptr : "",
Index: w3m/patches/patch-indep_h
===================================================================
RCS file: w3m/patches/patch-indep_h
diff -N w3m/patches/patch-indep_h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ w3m/patches/patch-indep_h   6 Jan 2015 09:16:56 -0000
@@ -0,0 +1,25 @@
+Use the overflow-detecting allocation macros from alloc.h
+
+--- indep.h.orig       Mon Jan  5 23:04:18 2015
++++ indep.h    Mon Jan  5 23:04:45 2015
+@@ -1,7 +1,7 @@
+ /* $Id: indep.h,v 1.16 2003/09/22 21:02:19 ukai Exp $ */
+ #ifndef INDEP_H
+ #define INDEP_H
+-#include <gc.h>
++#include "alloc.h"
+ #include "Str.h"
+ #include "config.h"
+ 
+@@ -70,11 +70,5 @@
+ extern char *w3m_etc_dir();
+ extern char *w3m_conf_dir();
+ extern char *w3m_help_dir();
+-
+-#define New(type)     ((type*)GC_MALLOC(sizeof(type)))
+-#define NewAtom(type) ((type*)GC_MALLOC_ATOMIC(sizeof(type)))
+-#define New_N(type,n) ((type*)GC_MALLOC((n)*sizeof(type)))
+-#define NewAtom_N(type,n)     ((type*)GC_MALLOC_ATOMIC((n)*sizeof(type)))
+-#define New_Reuse(type,ptr,n)   ((type*)GC_REALLOC((ptr),(n)*sizeof(type)))
+ 
+ #endif                                /* INDEP_H */
Index: w3m/patches/patch-libwc_charset_c
===================================================================
RCS file: w3m/patches/patch-libwc_charset_c
diff -N w3m/patches/patch-libwc_charset_c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ w3m/patches/patch-libwc_charset_c   6 Jan 2015 09:16:56 -0000
@@ -0,0 +1,14 @@
+Use the overflow-detecting allocation macros from alloc.h
+
+--- libwc/charset.c.orig       Mon Jan  5 23:06:56 2015
++++ libwc/charset.c    Mon Jan  5 23:07:25 2015
+@@ -1,8 +1,7 @@
+ 
+ #include <stdlib.h>
+ #include <ctype.h>
+-#include <gc.h>
+-#define New_N(type,n) ((type*)GC_MALLOC((n)*sizeof(type)))
++#include "../alloc.h"
+ 
+ #include "wc.h"
+ 
Index: w3m/patches/patch-libwc_status_c
===================================================================
RCS file: w3m/patches/patch-libwc_status_c
diff -N w3m/patches/patch-libwc_status_c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ w3m/patches/patch-libwc_status_c    6 Jan 2015 09:16:56 -0000
@@ -0,0 +1,13 @@
+Use the overflow-detecting allocation macros from alloc.h
+
+--- libwc/status.c.orig        Mon Jan  5 23:09:10 2015
++++ libwc/status.c     Mon Jan  5 23:12:39 2015
+@@ -1,7 +1,6 @@
+ 
+ #include <string.h>
+-#include <gc.h>
+-#define New_N(type,n) ((type*)GC_MALLOC((n)*sizeof(type)))
++#include "../alloc.h"
+ 
+ #include "wc.h"
+ #ifdef USE_UNICODE
Index: w3m/patches/patch-local_c
===================================================================
RCS file: w3m/patches/patch-local_c
diff -N w3m/patches/patch-local_c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ w3m/patches/patch-local_c   6 Jan 2015 09:16:56 -0000
@@ -0,0 +1,13 @@
+Fix for a directory descriptor leak, from max at suse dot de
+https://build.opensuse.org/package/view_file/openSUSE:Factory/w3m/w3m-closedir.patch?expand=1
+
+--- local.c.orig       Mon Jan  5 22:05:35 2015
++++ local.c    Mon Jan  5 22:06:33 2015
+@@ -109,6 +109,7 @@
+           n++;
+       }
+     }
++    (void)closedir(d);
+ 
+     if (multicolList) {
+       l = COLS / (maxlen + 2);
Index: w3m/patches/patch-main_c
===================================================================
RCS file: /cvs/ports/www/w3m/patches/patch-main_c,v
retrieving revision 1.1
diff -u -p -u -r1.1 patch-main_c
--- w3m/patches/patch-main_c    1 Jun 2013 21:06:20 -0000       1.1
+++ w3m/patches/patch-main_c    6 Jan 2015 09:16:56 -0000
@@ -1,7 +1,34 @@
 $OpenBSD: patch-main_c,v 1.1 2013/06/01 21:06:20 kurt Exp $
---- main.c.orig        Thu May 30 12:31:09 2013
-+++ main.c     Thu May 30 12:32:02 2013
-@@ -833,7 +833,9 @@ main(int argc, char **argv, char **envp)
+
+Call exit(1) when out of memory to avoid dereferencing null pointers
+when gc's malloc fails. Update warn_proc for new gc API, and print
+a long int using the correct format specifier.
+
+--- main.c.orig        Tue Jan  4 03:42:19 2011
++++ main.c     Mon Jan  5 22:33:28 2015
+@@ -372,6 +372,13 @@
+     return hs;
+ }
+ 
++static void *
++die_oom(size_t bytes)
++{
++    fprintf(stderr, "Out of memory: %zu bytes unavailable!\n", bytes);
++    exit(1);
++}
++
+ int
+ main(int argc, char **argv, char **envp)
+ {
+@@ -398,6 +405,7 @@
+ #endif
+ #endif
+     GC_INIT();
++    GC_set_oom_fn(die_oom);
+ #if defined(ENABLE_NLS) || (defined(USE_M17N) && 
defined(HAVE_LANGINFO_CODESET))
+     setlocale(LC_ALL, "");
+ #endif
+@@ -833,7 +841,9 @@
      mySignal(SIGPIPE, SigPipe);
  #endif
  
@@ -12,3 +39,12 @@ $OpenBSD: patch-main_c,v 1.1 2013/06/01 
      err_msg = Strnew();
      if (load_argc == 0) {
        /* no URL specified */
+@@ -5671,7 +5681,7 @@
+           set_environ("W3M_CURRENT_FORM", form2str((FormItemList *)a->url));
+       else
+           set_environ("W3M_CURRENT_FORM", "");
+-      set_environ("W3M_CURRENT_LINE", Sprintf("%d",
++      set_environ("W3M_CURRENT_LINE", Sprintf("%ld",
+                                               l->real_linenumber)->ptr);
+       set_environ("W3M_CURRENT_COLUMN", Sprintf("%d",
+                                                 buf->currentColumn +
Index: w3m/patches/patch-map_c
===================================================================
RCS file: w3m/patches/patch-map_c
diff -N w3m/patches/patch-map_c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ w3m/patches/patch-map_c     6 Jan 2015 09:16:56 -0000
@@ -0,0 +1,13 @@
+Print size_t using the correct format specifier
+
+--- map.c.orig Mon Jan  5 22:37:07 2015
++++ map.c      Mon Jan  5 22:37:52 2015
+@@ -581,7 +581,7 @@
+                  "<tr valign=top><td nowrap>Number of lines<td>",
+                  Sprintf("%d", all)->ptr,
+                  "<tr valign=top><td nowrap>Transferred bytes<td>",
+-                 Sprintf("%d", buf->trbyte)->ptr, NULL);
++                 Sprintf("%zu", buf->trbyte)->ptr, NULL);
+ 
+     a = retrieveCurrentAnchor(buf);
+     if (a != NULL) {
Index: w3m/patches/patch-parsetagx_c
===================================================================
RCS file: w3m/patches/patch-parsetagx_c
diff -N w3m/patches/patch-parsetagx_c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ w3m/patches/patch-parsetagx_c       6 Jan 2015 09:16:56 -0000
@@ -0,0 +1,14 @@
+Fix for a null pointer deref when parsing "<input type>" in HTML,
+from olh at suse dot de
+https://build.opensuse.org/package/view_file/openSUSE:Factory/w3m/w3m-parsetagx-crash.patch?expand=1
+
+--- parsetagx.c.orig   Mon Jan  5 22:02:56 2015
++++ parsetagx.c        Mon Jan  5 22:03:35 2015
+@@ -221,6 +221,7 @@
+          int j, hidden=FALSE;
+          for (j=0; j<i; j++) {
+            if (tag->attrid[j] == ATTR_TYPE &&
++               tag->value[j] != NULL &&
+                strcmp("hidden",tag->value[j]) == 0) {
+              hidden=TRUE;
+              break;
Index: w3m/patches/patch-w3mbookmark_c
===================================================================
RCS file: w3m/patches/patch-w3mbookmark_c
diff -N w3m/patches/patch-w3mbookmark_c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ w3m/patches/patch-w3mbookmark_c     6 Jan 2015 09:16:56 -0000
@@ -0,0 +1,15 @@
+Use %s to print a string instead of passing it as the format string
+to fprintf(), from Colin Watson at Ubuntu
+http://anonscm.debian.org/cgit/collab-maint/w3m.git/commit/?h=bug/646321
+
+--- w3mbookmark.c.orig Mon Jan  5 21:59:29 2015
++++ w3mbookmark.c      Mon Jan  5 21:59:55 2015
+@@ -99,7 +99,7 @@
+       fprintf(f, "<body>\n<h1>Bookmarks</h1>\n");
+       fprintf(f, "<h2>%s</h2>\n<ul>\n", section);
+       fprintf(f, "<li><a href=\"%s\">%s</a>\n", url, title);
+-      fprintf(f, end_section);
++      fprintf(f, "%s", end_section);
+       fprintf(f, "</ul>\n</body>\n</html>\n");
+       fclose(f);
+     }

Reply via email to