Index: texk/dvi2tty/dvi2tty-5.3.4-PATCHES/patch-05-win32
===================================================================
--- texk/dvi2tty/dvi2tty-5.3.4-PATCHES/patch-05-win32	(revision 0)
+++ texk/dvi2tty/dvi2tty-5.3.4-PATCHES/patch-05-win32	(revision 0)
@@ -0,0 +1,12 @@
+diff -ur dvi2tty-5.3.4.orig/dvi2tty.h dvi2tty-5.3.4/dvi2tty.h
+--- dvi2tty-5.3.4.orig/dvi2tty.h	2011-11-21 22:28:42.000000000 +0100
++++ dvi2tty-5.3.4/dvi2tty.h	2012-06-22 09:09:35.000000000 +0200
+@@ -28,7 +28,7 @@
+ #include <stdio.h>
+ #include <string.h>
+ #include <stdlib.h>
+-#if defined(MSDOS)
++#if defined(MSDOS) || (defined(WIN32) && !defined(__MINGW32__))
+ # include <malloc.h>
+ #else
+ # if !defined(THINK_C)
Index: texk/dvi2tty/dvi2tty-5.3.4-PATCHES/ChangeLog
===================================================================
--- texk/dvi2tty/dvi2tty-5.3.4-PATCHES/ChangeLog	(revision 26897)
+++ texk/dvi2tty/dvi2tty-5.3.4-PATCHES/ChangeLog	(working copy)
@@ -1,3 +1,12 @@
+2012-06-22  Peter Breitenlohner   <peb@mppmu.mpg.de>
+
+	* patch-05-win32 (new): WIN32 MSVC lacks <unistd.h> and requires
+	<malloc.h>.
+
+	* patch-06-malloc (new): Avoid buffer overrun for long pathnames
+	(detected by Ken Brown <kbrow1i@gmail.com>),
+	and check all values returned by malloc().
+
 2012-04-26  Peter Breitenlohner   <peb@mppmu.mpg.de>
 
 	* patch-04-OpenSolaris: New patch:
Index: texk/dvi2tty/dvi2tty-5.3.4-PATCHES/patch-06-malloc
===================================================================
--- texk/dvi2tty/dvi2tty-5.3.4-PATCHES/patch-06-malloc	(revision 0)
+++ texk/dvi2tty/dvi2tty-5.3.4-PATCHES/patch-06-malloc	(revision 0)
@@ -0,0 +1,70 @@
+diff -ur dvi2tty-5.3.4.orig/disdvi.c dvi2tty-5.3.4/disdvi.c
+--- dvi2tty-5.3.4.orig/disdvi.c	2010-11-13 16:31:14.000000000 +0100
++++ dvi2tty-5.3.4/disdvi.c	2012-06-22 09:12:43.000000000 +0200
+@@ -193,7 +193,10 @@
+         if ((i >= 5) && (!strcmp(*argv+i-4, dvi_ext)))
+             dvi_name = *argv;
+         else {
+-            dvi_name = malloc((i+5) * sizeof(char));
++            if ((dvi_name = malloc((i+5) * sizeof(char))) == NULL) {
++                perror("dvi_name");
++                exit(1);
++            }
+             strcpy(dvi_name, *argv);
+             strcat(dvi_name, dvi_ext);
+         }
+diff -ur dvi2tty-5.3.4.orig/dvi2tty.c dvi2tty-5.3.4/dvi2tty.c
+--- dvi2tty-5.3.4.orig/dvi2tty.c	2011-11-21 22:30:24.000000000 +0100
++++ dvi2tty-5.3.4/dvi2tty.c	2012-06-22 10:12:43.000000000 +0200
+@@ -53,7 +53,6 @@
+ 
+     /*------------------ end of customization constants ---------------------*/
+ 
+-#define MAXLEN          100    /* size of char-arrays for strings            */
+ #if defined(MSDOS) || defined(VMS) || defined(AMIGA)
+ #define OPTSET      "haJweEpPousltvbcANU" /* legal options                   */
+ #define OPTWARG     "weEpPovb"  /* options with argument                     */
+@@ -109,7 +108,7 @@
+ char  *         progname;       /* our name                                  */
+ int             Argc;
+ char **         Argv;
+-char            DVIfilename[MAXLEN];
++char  *         DVIfilename;
+ const char *    OUTfilename;
+ char            optch;          /* for option handling                       */
+ 
+@@ -483,7 +482,10 @@
+     int num;
+ 
+     pageswitchon = TRUE;
+-    firstpage = (printlisttype *) malloc(sizeof(printlisttype));
++    if ((firstpage = (printlisttype *) malloc(sizeof(printlisttype))) == NULL) {
++        perror("firstpage");
++        exit(1);
++    }
+     firstpage->all = FALSE;
+     firstpage->nxt = nil;
+     firstpage->pag = 0;
+@@ -543,7 +545,10 @@
+ 
+     currentpage = lastpage;
+     currentpage->pag = pagnr;
+-    lastpage = (printlisttype *) malloc(sizeof(printlisttype));
++    if ((lastpage = (printlisttype *) malloc(sizeof(printlisttype))) == NULL) {
++        perror("lastpage");
++        exit(1);
++    }
+     lastpage->all = FALSE;
+     lastpage->nxt = nil;
+     lastpage->pag = 0;
+@@ -566,6 +571,10 @@
+     i = strlen(str);
+     if (i == 0)
+         usage(ign);
++    if ((DVIfilename = (char *) malloc(i+5)) == NULL) {
++        perror("DVIfilename");
++        exit(1);
++    }
+     strcpy(DVIfilename, str);
+ #ifdef KPATHSEA
+     if (!kpse_readable_file(DVIfilename))
Index: texk/dvi2tty/dvi2tty-5.3.4/dvi2tty.c
===================================================================
--- texk/dvi2tty/dvi2tty-5.3.4/dvi2tty.c	(revision 26897)
+++ texk/dvi2tty/dvi2tty-5.3.4/dvi2tty.c	(working copy)
@@ -53,7 +53,6 @@
 
     /*------------------ end of customization constants ---------------------*/
 
-#define MAXLEN          100    /* size of char-arrays for strings            */
 #if defined(MSDOS) || defined(VMS) || defined(AMIGA)
 #define OPTSET      "haJweEpPousltvbcANU" /* legal options                   */
 #define OPTWARG     "weEpPovb"  /* options with argument                     */
@@ -109,7 +108,7 @@
 char  *         progname;       /* our name                                  */
 int             Argc;
 char **         Argv;
-char            DVIfilename[MAXLEN];
+char  *         DVIfilename;
 const char *    OUTfilename;
 char            optch;          /* for option handling                       */
 
@@ -483,7 +482,10 @@
     int num;
 
     pageswitchon = TRUE;
-    firstpage = (printlisttype *) malloc(sizeof(printlisttype));
+    if ((firstpage = (printlisttype *) malloc(sizeof(printlisttype))) == NULL) {
+        perror("firstpage");
+        exit(1);
+    }
     firstpage->all = FALSE;
     firstpage->nxt = nil;
     firstpage->pag = 0;
@@ -543,7 +545,10 @@
 
     currentpage = lastpage;
     currentpage->pag = pagnr;
-    lastpage = (printlisttype *) malloc(sizeof(printlisttype));
+    if ((lastpage = (printlisttype *) malloc(sizeof(printlisttype))) == NULL) {
+        perror("lastpage");
+        exit(1);
+    }
     lastpage->all = FALSE;
     lastpage->nxt = nil;
     lastpage->pag = 0;
@@ -566,6 +571,10 @@
     i = strlen(str);
     if (i == 0)
         usage(ign);
+    if ((DVIfilename = (char *) malloc(i+5)) == NULL) {
+        perror("DVIfilename");
+        exit(1);
+    }
     strcpy(DVIfilename, str);
 #ifdef KPATHSEA
     if (!kpse_readable_file(DVIfilename))
Index: texk/dvi2tty/dvi2tty-5.3.4/dvi2tty.h
===================================================================
--- texk/dvi2tty/dvi2tty-5.3.4/dvi2tty.h	(revision 26897)
+++ texk/dvi2tty/dvi2tty-5.3.4/dvi2tty.h	(working copy)
@@ -28,7 +28,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
-#if defined(MSDOS)
+#if defined(MSDOS) || (defined(WIN32) && !defined(__MINGW32__))
 # include <malloc.h>
 #else
 # if !defined(THINK_C)
Index: texk/dvi2tty/dvi2tty-5.3.4/disdvi.c
===================================================================
--- texk/dvi2tty/dvi2tty-5.3.4/disdvi.c	(revision 26897)
+++ texk/dvi2tty/dvi2tty-5.3.4/disdvi.c	(working copy)
@@ -193,7 +193,10 @@
         if ((i >= 5) && (!strcmp(*argv+i-4, dvi_ext)))
             dvi_name = *argv;
         else {
-            dvi_name = malloc((i+5) * sizeof(char));
+            if ((dvi_name = malloc((i+5) * sizeof(char))) == NULL) {
+                perror("dvi_name");
+                exit(1);
+            }
             strcpy(dvi_name, *argv);
             strcat(dvi_name, dvi_ext);
         }
