summaryrefslogtreecommitdiff
path: root/ftp/curl/files/patch-src::main.c
blob: 6322e688d9d9550fedf816fe79c12ed16da40dc2 (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
diff -urN -urN -x .svn ../../vendor/curl/src/main.c ./src/main.c
--- ../../vendor/curl/src/main.c	2008-03-24 00:40:11.000000000 +0200
+++ ./src/main.c	2008-04-02 15:51:11.000000000 +0300
@@ -4190,31 +4190,32 @@
              (-1 == create_dir_hierarchy(outfile)))
             return CURLE_WRITE_ERROR;
 
-          if(config->resume_from_current) {
-            /* We're told to continue from where we are now. Get the
-               size of the file as it is now and open it for append instead */
-
-            struct_stat fileinfo;
-
-            /* VMS -- Danger, the filesize is only valid for stream files */
-            if(0 == stat(outfile, &fileinfo))
-              /* set offset to current file size: */
-              config->resume_from = fileinfo.st_size;
-            else
-              /* let offset be 0 */
-              config->resume_from = 0;
-          }
-
           outs.filename = outfile;
 
-          if(config->resume_from) {
-            outs.init = config->resume_from;
+          if(config->resume_from || config->resume_from_current) {
             /* open file for output: */
-            outs.stream=(FILE *) fopen(outfile, config->resume_from?"ab":"wb");
+	    /* (always open for appending, it has no effect on new files) */
+            outs.stream=(FILE *) fopen(outfile, "ab");
             if (!outs.stream) {
               helpf("Can't open '%s'!\n", outfile);
               return CURLE_WRITE_ERROR;
             }
+
+	    if(config->resume_from_current) {
+	      /* We're told to continue from where we are now. Get the
+                 size of the file as it is now */
+
+	      struct_stat fileinfo;
+
+              if(0 == fstat(fileno(outs.stream), &fileinfo))
+                /* set offset to current file size: */
+                config->resume_from = fileinfo.st_size;
+              else
+                /* let offset be 0 */
+                config->resume_from = 0;
+	    }
+
+            outs.init = config->resume_from;
           }
           else {
             outs.stream = NULL; /* open when needed */
@@ -4289,7 +4290,7 @@
            */
 
           infd= open(uploadfile, O_RDONLY | O_BINARY);
-          if ((infd == -1) || stat(uploadfile, &fileinfo)) {
+          if ((infd == -1) || fstat(infd, &fileinfo)) {
             helpf("Can't open '%s'!\n", uploadfile);
             if(infd != -1)
               close(infd);
@@ -5155,12 +5156,13 @@
 const char *
 msdosify (const char *file_name)
 {
-  static char dos_name[PATH_MAX];
+  static char dos_name[PATH_MAX + 16];
   static const char illegal_chars_dos[] = ".+, ;=[]|<>\\\":?*";
   static const char *illegal_chars_w95 = &illegal_chars_dos[8];
   int idx, dot_idx;
   const char *s = file_name;
   char *d = dos_name;
+  char *dlimit = dos_name + PATH_MAX;
   const char *illegal_aliens = illegal_chars_dos;
   size_t len = sizeof (illegal_chars_dos) - 1;
   int lfn = 0;
@@ -5181,7 +5183,7 @@
     *d++ = *s++;
   }
 
-  for (idx = 0, dot_idx = -1; *s; s++, d++) {
+  for (idx = 0, dot_idx = -1; *s && d < dlimit; s++, d++) {
     if (memchr (illegal_aliens, *s, len)) {
       /* Dots are special: DOS doesn't allow them as the leading character,
          and a file name cannot have more than a single dot.  We leave the
@@ -5238,6 +5240,10 @@
       idx++;
   }
 
+  if(d >= dlimit) {
+    /* should some kind of error be raised? */
+    d = dlimit - 1;
+  }
   *d = '\0';
   return dos_name;
 }
@@ -5252,11 +5258,15 @@
   struct stat st_buf;
   char fname[PATH_MAX];
 
-  strcpy (fname, file_name);
+  snprintf (fname, PATH_MAX, "%s", file_name);
   base = basename (fname);
   if (((stat(base, &st_buf)) == 0) && (S_ISCHR(st_buf.st_mode))) {
-    size_t blen = strlen (base);
+    size_t blen = strlen (base), flen = strlen (fname);
 
+    if(flen == PATH_MAX - 1) {
+      blen--;
+      base[blen] = '\0';
+    }
     /* Prepend a '_'.  */
     memmove (base + 1, base, blen + 1);
     base[0] = '_';