2 This patch fixes the strippath bug that created a buffer overrun and thus
3 a crash in the FD. It fixes bug #1078.
5 Apply it to version 2.2.8 or higher with:
8 patch -p0 <2.2.8-strippath.patch
9 ./configure <your options>
15 Index: src/filed/backup.c
16 ===================================================================
17 --- src/filed/backup.c (revision 6843)
18 +++ src/filed/backup.c (working copy)
21 /* Copy to first path separator -- Win32 might have c: ... */
22 while (*in && !IsPathSeparator(*in)) {
28 numsep++; /* one separator seen */
29 for (stripped=0; stripped<count && *in; stripped++) {
30 while (*in && !IsPathSeparator(*in)) {
31 @@ -1129,7 +1129,11 @@
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.
42 static void strip_path(FF_PKT *ff_pkt)
44 @@ -1142,27 +1146,35 @@
45 ff_pkt->link_save = get_pool_memory(PM_FNAME);
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);
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
60 - * Don't strip symlinks.
61 + * Do not strip symlinks.
62 * I.e. if either stripping fails don't strip anything.
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);
71 + if (!do_strip(ff_pkt->strip_path, ff_pkt->fname)) {
72 + unstrip_path(ff_pkt);
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);
81 - strcpy(ff_pkt->fname, ff_pkt->fname_save);
83 - Dmsg2(200, "fname=%s stripped=%s\n", ff_pkt->fname_save, ff_pkt->fname);
87 + Dmsg3(100, "fname=%s stripped=%s link=%s\n", ff_pkt->fname_save, ff_pkt->fname,
91 static void unstrip_path(FF_PKT *ff_pkt)
92 @@ -1172,6 +1184,11 @@
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,
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);