]> TLD Linux GIT Repositories - packages/dialog.git/blob - escaping_fix.patch
- revert escaping changes, breaks existing code
[packages/dialog.git] / escaping_fix.patch
1 diff -ur dialog-1.3-20160209.orig/argv.c dialog-1.3-20160209/argv.c
2 --- dialog-1.3-20160209.orig/argv.c     2015-05-13 00:34:39.000000000 +0000
3 +++ dialog-1.3-20160209/argv.c  2016-02-11 10:41:08.705828223 +0000
4 @@ -55,12 +55,18 @@
5                     ++count;
6                     inparm = TRUE;
7                 }
8 -           } else if (!quoted && isspace(UCH(blob[n]))) {
9 -               if (inparm) {
10 +           } else if (blob[n] == '\\') {
11 +               if (quoted && !isspace(UCH(blob[n + 1]))) {
12                     if (pass) {
13 -                       *param++ = '\0';
14 +                       *param++ = blob[n];
15 +                       *param++ = blob[n + 1];
16                     }
17 -                   inparm = FALSE;
18 +               }
19 +               ++n;
20 +           } else if (!quoted && isspace(UCH(blob[n]))) {
21 +               inparm = FALSE;
22 +               if (pass) {
23 +                   *param++ = '\0';
24                 }
25             } else {
26                 if (!inparm) {
27 @@ -69,10 +75,6 @@
28                     ++count;
29                     inparm = TRUE;
30                 }
31 -               if (blob[n] == '\\') {
32 -                   if (++n == length)
33 -                       break;  /* The string is terminated by a backslash */
34 -               }
35                 if (pass) {
36                     *param++ = blob[n];
37                 }
38 diff -ur dialog-1.3-20160209.orig/dialog.c dialog-1.3-20160209/dialog.c
39 --- dialog-1.3-20160209.orig/dialog.c   2016-02-09 00:05:39.000000000 +0000
40 +++ dialog-1.3-20160209/dialog.c        2016-02-11 10:41:08.707828223 +0000
41 @@ -421,58 +421,49 @@
42                     blob[length] = '\0';
43  
44                     list = dlg_string_to_argv(blob);
45 -                   added = dlg_count_argv(list);
46 -                   if (added > 2) {
47 -                       /* *argcp arguments before the expansion of --file
48 -                          - 2 for the removal of '--file <filepath>'
49 -                          + added for the arguments contained in <filepath>
50 -                          + 1 for the terminating NULL pointer */
51 -                       size_t need = (size_t) (*argcp + added - 1);
52 -                       if (doalloc) {
53 -                           *argvp = dlg_realloc(char *, need, *argvp);
54 -                           assert_ptr(*argvp, "unescape_argv");
55 -                       } else {
56 -                           char **newp = dlg_malloc(char *, need);
57 -                           assert_ptr(newp, "unescape_argv");
58 -                           for (n = 0; n < *argcp; ++n) {
59 -                               newp[n] = (*argvp)[n];
60 +                   if ((added = dlg_count_argv(list)) != 0) {
61 +                       if (added > 2) {
62 +                           size_t need = (size_t) (*argcp + added + 1);
63 +                           if (doalloc) {
64 +                               *argvp = dlg_realloc(char *, need, *argvp);
65 +                               assert_ptr(*argvp, "unescape_argv");
66 +                           } else {
67 +                               char **newp = dlg_malloc(char *, need);
68 +                               assert_ptr(newp, "unescape_argv");
69 +                               for (n = 0; n < *argcp; ++n) {
70 +                                   newp[n] = (*argvp)[n];
71 +                               }
72 +                               *argvp = newp;
73 +                               doalloc = TRUE;
74                             }
75 -                           /* The new array is not NULL-terminated yet. */
76 -                           *argvp = newp;
77 -                           doalloc = TRUE;
78 +                           dialog_opts = dlg_realloc(bool, need, dialog_opts);
79 +                           assert_ptr(dialog_opts, "unescape_argv");
80                         }
81 -                       dialog_opts = dlg_realloc(bool, need, dialog_opts);
82 -                       assert_ptr(dialog_opts, "unescape_argv");
83 -
84 -                       /* Shift the arguments after '--file <filepath>'
85 -                          right by (added - 2) positions */
86 -                       for (n = *argcp - 1; n >= j + 2; --n) {
87 -                           (*argvp)[n + added - 2] = (*argvp)[n];
88 -                           dialog_opts[n + added - 2] = dialog_opts[n];
89 +                       if (added > 2) {
90 +                           for (n = *argcp; n >= j + 2; --n) {
91 +                               (*argvp)[n + added - 2] = (*argvp)[n];
92 +                               dialog_opts[n + added - 2] = dialog_opts[n];
93 +                           }
94 +                       } else if (added == 1) {
95 +                           for (n = j; n < *argcp; ++n) {
96 +                               (*argvp)[n] = (*argvp)[n + 1];
97 +                               dialog_opts[n] = dialog_opts[n + 1];
98 +                           }
99                         }
100 -                   } else if (added < 2) {
101 -                       /* 0 or 1 argument read from the included file
102 -                          -> shift the arguments after '--file <filepath>'
103 -                          left by (2 - added) positions */
104 -                       for (n = j + added; n + 2 - added < *argcp; ++n) {
105 -                           (*argvp)[n] = (*argvp)[n + 2 - added];
106 -                           dialog_opts[n] = dialog_opts[n + 2 - added];
107 +                       for (n = 0; n < added; ++n) {
108 +                           (*argvp)[n + j] = list[n];
109 +                           dialog_opts[n + j] = FALSE;
110                         }
111 +                       *argcp += added - 2;
112 +                       free(list);
113 +                       --j;    /* force rescan */
114                     }
115 -                   /* Copy the inserted arguments to *argvp */
116 -                   for (n = 0; n < added; ++n) {
117 -                       (*argvp)[n + j] = list[n];
118 -                       dialog_opts[n + j] = FALSE;
119 -                   }
120 -                   *argcp += added - 2;
121 -                   (*argvp)[*argcp] = 0;       /* Write the NULL terminator */
122 -                   free(list); /* No-op if 'list' is NULL */
123 -                   /* Force rescan starting from the first inserted argument */
124 -                   --j;
125 -                   continue;
126                 } else {
127                     dlg_exiterr("Cannot open --file %s", filename);
128                 }
129 +               (*argvp)[*argcp] = 0;
130 +               ++j;
131 +               continue;
132             } else {
133                 dlg_exiterr("No value given for --file");
134             }