]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/2.2.8-strippath.patch
kes Fix strippath so that it does not get a buffer overrun and crash FD.
[bacula/bacula] / bacula / patches / 2.2.8-strippath.patch
1  
2   This patch fixes the strippath bug that created a buffer overrun and thus
3   a crash in the FD.  It fixes bug #1078.
4
5   Apply it to version 2.2.8 or higher with:
6
7   cd <bacula-source>
8   patch -p0 <2.2.8-strippath.patch
9   ./configure <your options>
10   make
11   ...
12   make install
13
14
15 Index: src/filed/backup.c
16 ===================================================================
17 --- src/filed/backup.c  (revision 6843)
18 +++ src/filed/backup.c  (working copy)
19 @@ -1102,9 +1102,9 @@
20  
21     /* Copy to first path separator -- Win32 might have c: ... */
22     while (*in && !IsPathSeparator(*in)) {    
23 -      *out++ = *in++;
24 +      out++; in++;
25     }
26 -   *out++ = *in++;
27 +   out++; in++;
28     numsep++;                     /* one separator seen */
29     for (stripped=0; stripped<count && *in; stripped++) {
30        while (*in && !IsPathSeparator(*in)) {
31 @@ -1129,7 +1129,11 @@
32  }
33  
34  /*
35 - * If requested strip leading components of the path
36 + * If requested strip leading components of the path so that we can
37 + *   save file as if it came from a subdirectory.  This is most useful
38 + *   for dealing with snapshots, by removing the snapshot directory, or
39 + *   in handling vendor migrations where files have been restored with
40 + *   a vendor product into a subdirectory.
41   */
42  static void strip_path(FF_PKT *ff_pkt)
43  {
44 @@ -1142,27 +1146,35 @@
45       ff_pkt->link_save = get_pool_memory(PM_FNAME);
46     }
47     pm_strcpy(ff_pkt->fname_save, ff_pkt->fname);
48 +   if (ff_pkt->type != FT_LNK && ff_pkt->fname != ff_pkt->link) {
49 +      pm_strcpy(ff_pkt->link_save, ff_pkt->link);
50 +      Dmsg2(500, "strcpy link_save=%d link=%d\n", strlen(ff_pkt->link_save),
51 +         strlen(ff_pkt->link));
52 +      sm_check(__FILE__, __LINE__, true);
53 +   }
54  
55     /* 
56      * Strip path.  If it doesn't succeed put it back.  If
57      *  it does, and there is a different link string,
58      *  attempt to strip the link. If it fails, back them
59      *  both back.
60 -    * Don't strip symlinks.
61 +    * Do not strip symlinks.
62      * I.e. if either stripping fails don't strip anything.
63      */
64 -   if (do_strip(ff_pkt->strip_path, ff_pkt->fname)) {
65 -      if (ff_pkt->type != FT_LNK && ff_pkt->fname != ff_pkt->link) {
66 -         pm_strcpy(ff_pkt->link_save, ff_pkt->link);
67 -         if (!do_strip(ff_pkt->strip_path, ff_pkt->link)) {
68 -            strcpy(ff_pkt->link, ff_pkt->link_save);
69 -            strcpy(ff_pkt->fname, ff_pkt->fname_save);
70 -         }
71 +   if (!do_strip(ff_pkt->strip_path, ff_pkt->fname)) {
72 +      unstrip_path(ff_pkt);
73 +      goto rtn;
74 +   } 
75 +   /* Strip links but not symlinks */
76 +   if (ff_pkt->type != FT_LNK && ff_pkt->fname != ff_pkt->link) {
77 +      if (!do_strip(ff_pkt->strip_path, ff_pkt->link)) {
78 +         unstrip_path(ff_pkt);
79        }
80 -   } else {
81 -      strcpy(ff_pkt->fname, ff_pkt->fname_save);
82 -   } 
83 -   Dmsg2(200, "fname=%s stripped=%s\n", ff_pkt->fname_save, ff_pkt->fname);
84 +   }
85 +
86 +rtn:
87 +   Dmsg3(100, "fname=%s stripped=%s link=%s\n", ff_pkt->fname_save, ff_pkt->fname, 
88 +       ff_pkt->link);
89  }
90  
91  static void unstrip_path(FF_PKT *ff_pkt)
92 @@ -1172,6 +1184,11 @@
93     }
94     strcpy(ff_pkt->fname, ff_pkt->fname_save);
95     if (ff_pkt->type != FT_LNK && ff_pkt->fname != ff_pkt->link) {
96 +      Dmsg2(500, "strcpy link=%s link_save=%s\n", ff_pkt->link,
97 +          ff_pkt->link_save);
98        strcpy(ff_pkt->link, ff_pkt->link_save);
99 +      Dmsg2(500, "strcpy link=%d link_save=%d\n", strlen(ff_pkt->link),
100 +          strlen(ff_pkt->link_save));
101 +      sm_check(__FILE__, __LINE__, true);
102     }
103  }