summary refs log tree commit diff
path: root/pkgs/tools/text/unix2dos/unix2dos-2.2-segfault.patch
blob: a92f57cfe70c7bfe40fb1a5282985fa2d801c59d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
--- unix2dos-2.2/unix2dos.c.segf	Thu Jan 17 17:09:49 2002
+++ unix2dos-2.2/unix2dos.c	Thu Jan 17 17:12:47 2002
@@ -131,9 +131,9 @@
  * RetVal: NULL if failure
  *         file stream otherwise
  */
-FILE* OpenOutFile(char *ipFN)
+FILE* OpenOutFile(int fd)
 {
-  return (fopen(ipFN, W_CNTRL));
+  return (fdopen(fd, W_CNTRL));
 }
 
 
@@ -207,14 +207,17 @@
   char TempPath[16];
   struct stat StatBuf;
   struct utimbuf UTimeBuf;
+  int fd;
 
   /* retrieve ipInFN file date stamp */
   if ((ipFlag->KeepDate) && stat(ipInFN, &StatBuf))
     RetVal = -1;
 
-  strcpy (TempPath, "./u2dtmp");
-  strcat (TempPath, "XXXXXX");
-  mkstemp (TempPath);
+  strcpy (TempPath, "./u2dtmpXXXXXX");
+  if((fd=mkstemp (TempPath)) < 0) {
+	  perror("Can't open output temp file");
+	  RetVal = -1;
+  }
 
 #ifdef DEBUG
   fprintf(stderr, "unix2dos: using %s as temp file\n", TempPath);
@@ -225,7 +228,7 @@
     RetVal = -1;
 
   /* can open out file? */
-  if ((!RetVal) && (InF) && ((TempF=OpenOutFile(TempPath)) == NULL))
+  if ((!RetVal) && (InF) && ((TempF=OpenOutFile(fd)) == NULL))
   {
     fclose (InF);
     RetVal = -1;
@@ -243,6 +246,9 @@
   if ((TempF) && (fclose(TempF) == EOF))
     RetVal = -1;
 
+  if(fd>=0)
+	  close(fd);
+
   if ((!RetVal) && (ipFlag->KeepDate))
   {
     UTimeBuf.actime = StatBuf.st_atime;
@@ -286,14 +292,17 @@
   char TempPath[16];
   struct stat StatBuf;
   struct utimbuf UTimeBuf;
+  int fd;
 
   /* retrieve ipInFN file date stamp */
   if ((ipFlag->KeepDate) && stat(ipInFN, &StatBuf))
     RetVal = -1;
 
-  strcpy (TempPath, "./u2dtmp");
-  strcat (TempPath, "XXXXXX");
-  mkstemp (TempPath);
+  strcpy (TempPath, "./u2dtmpXXXXXX");
+  if((fd=mkstemp (TempPath)) < 0) {
+      perror("Can't open output temp file");
+      RetVal = -1;
+  }
 
 #ifdef DEBUG
   fprintf(stderr, "unix2dos: using %s as temp file\n", TempPath);
@@ -304,7 +313,7 @@
     RetVal = -1;
 
   /* can open out file? */
-  if ((!RetVal) && (InF) && ((TempF=OpenOutFile(TempPath)) == NULL))
+  if ((!RetVal) && (InF) && ((TempF=OpenOutFile(fd)) == NULL))
   {
     fclose (InF);
     RetVal = -1;
@@ -322,6 +331,9 @@
   if ((TempF) && (fclose(TempF) == EOF))
     RetVal = -1;
 
+  if(fd>=0)
+	  close(fd);
+
   if ((!RetVal) && (ipFlag->KeepDate))
   {
     UTimeBuf.actime = StatBuf.st_atime;