1
#! /bin/sh /usr/share/dpatch/dpatch-run
2
## 02_empty_regex.dpatch by <jordi@debian.org>
4
## All lines beginning with `## DP:' are a description of the patch.
5
## DP: Fix segfaults on zero length regexes.
8
diff -urNad nano-1.3.11~/src/winio.c nano-1.3.11/src/winio.c
9
--- nano-1.3.11~/src/winio.c 2006-03-30 03:18:29.000000000 +0200
10
+++ nano-1.3.11/src/winio.c 2006-05-18 23:34:58.851916460 +0200
11
@@ -2383,10 +2383,8 @@
12
_("Refusing zero-length regex match"));
13
} else if (startmatch.rm_so < endpos &&
14
startmatch.rm_eo > startpos) {
15
- if (startmatch.rm_so <= startpos)
18
- x_start = strnlenpt(fileptr->data,
19
+ x_start = (startmatch.rm_so <= startpos) ? 0 :
20
+ strnlenpt(fileptr->data,
21
startmatch.rm_so) - start;
23
index = actual_x(converted, x_start);
24
@@ -2430,129 +2428,135 @@
26
start_line = start_line->prev;
28
- /* No start found, so skip to the next step. */
29
- if (start_line == NULL)
31
- /* Now start_line is the first line before fileptr
32
- * containing a start match. Is there a start on this
33
- * line not followed by an end on this line? */
36
- start_col += startmatch.rm_so;
37
- startmatch.rm_eo -= startmatch.rm_so;
38
- if (regexec(tmpcolor->end, start_line->data +
39
- start_col + startmatch.rm_eo, 0, NULL,
40
- (start_col + startmatch.rm_eo == 0) ? 0 :
41
- REG_NOTBOL) == REG_NOMATCH)
42
- /* No end found after this start. */
45
- if (regexec(tmpcolor->start, start_line->data +
46
- start_col, 1, &startmatch,
47
- REG_NOTBOL) == REG_NOMATCH)
48
- /* No later start on this line. */
49
+ if (startmatch.rm_so == startmatch.rm_eo) {
51
+ statusbar(_("Refusing zero-length regex match"));
53
+ /* No start found, so skip to the next step. */
54
+ if (start_line == NULL)
57
- /* Indeed, there is a start not followed on this line by
59
+ /* Now start_line is the first line before fileptr
60
+ * containing a start match. Is there a start on
61
+ * this line not followed by an end on this line? */
64
+ start_col += startmatch.rm_so;
65
+ startmatch.rm_eo -= startmatch.rm_so;
66
+ if (regexec(tmpcolor->end, start_line->data +
67
+ start_col + startmatch.rm_eo, 0, NULL,
68
+ (start_col + startmatch.rm_eo == 0) ?
69
+ 0 : REG_NOTBOL) == REG_NOMATCH)
70
+ /* No end found after this start. */
73
+ if (regexec(tmpcolor->start, start_line->data +
74
+ start_col, 1, &startmatch,
75
+ REG_NOTBOL) == REG_NOMATCH)
76
+ /* No later start on this line. */
79
+ /* Indeed, there is a start not followed on this
80
+ * line by an end. */
82
- /* We have already checked that there is no end before
83
- * fileptr and after the start. Is there an end after
84
- * the start at all? We don't paint unterminated
87
- while (end_line != NULL && regexec(tmpcolor->end,
88
+ /* We have already checked that there is no end
89
+ * before fileptr and after the start. Is there an
90
+ * end after the start at all? We don't paint
91
+ * unterminated starts. */
93
+ while (end_line != NULL && regexec(tmpcolor->end,
94
end_line->data, 1, &endmatch, 0) == REG_NOMATCH)
95
- end_line = end_line->next;
96
+ end_line = end_line->next;
98
- /* No end found, or it is too early. */
99
- if (end_line == NULL || (end_line == fileptr &&
100
+ /* No end found, or it is too early. */
101
+ if (end_line == NULL || (end_line == fileptr &&
102
endmatch.rm_eo <= startpos))
106
- /* Now paint the start of fileptr. */
107
- if (end_line != fileptr)
108
- /* If the start of fileptr is on a different line
109
- * from the end, paintlen is -1, meaning that
110
- * everything on the line gets painted. */
113
- /* Otherwise, paintlen is the expanded location of
114
- * the end of the match minus the expanded location
115
- * of the beginning of the page. */
116
- paintlen = actual_x(converted,
117
- strnlenpt(fileptr->data, endmatch.rm_eo) -
119
+ /* Now paint the start of fileptr. */
120
+ if (end_line != fileptr)
121
+ /* If the start of fileptr is on a different
122
+ * line from the end, paintlen is -1, meaning
123
+ * that everything on the line gets painted. */
126
+ /* Otherwise, paintlen is the expanded location
127
+ * of the end of the match minus the expanded
128
+ * location of the beginning of the page. */
129
+ paintlen = actual_x(converted,
130
+ strnlenpt(fileptr->data,
131
+ endmatch.rm_eo) - start);
133
- mvwaddnstr(edit, line, 0, converted, paintlen);
134
+ mvwaddnstr(edit, line, 0, converted, paintlen);
137
- /* Second step, we look for starts on this line. */
139
+ /* Second step, we look for starts on this line. */
142
- while (start_col < endpos) {
143
- if (regexec(tmpcolor->start, fileptr->data +
144
- start_col, 1, &startmatch, (start_col == 0) ?
145
- 0 : REG_NOTBOL) == REG_NOMATCH || start_col +
146
- startmatch.rm_so >= endpos)
147
- /* No more starts on this line. */
149
- /* Translate the match to be relative to the
150
- * beginning of the line. */
151
- startmatch.rm_so += start_col;
152
- startmatch.rm_eo += start_col;
153
+ while (start_col < endpos) {
154
+ if (regexec(tmpcolor->start, fileptr->data +
155
+ start_col, 1, &startmatch, (start_col ==
156
+ 0) ? 0 : REG_NOTBOL) == REG_NOMATCH ||
157
+ start_col + startmatch.rm_so >= endpos)
158
+ /* No more starts on this line. */
160
+ /* Translate the match to be relative to the
161
+ * beginning of the line. */
162
+ startmatch.rm_so += start_col;
163
+ startmatch.rm_eo += start_col;
165
- if (startmatch.rm_so <= startpos)
168
- x_start = strnlenpt(fileptr->data,
169
+ x_start = (startmatch.rm_so <= startpos) ? 0 :
170
+ strnlenpt(fileptr->data,
171
startmatch.rm_so) - start;
173
- index = actual_x(converted, x_start);
174
+ index = actual_x(converted, x_start);
176
- if (regexec(tmpcolor->end, fileptr->data +
177
- startmatch.rm_eo, 1, &endmatch,
178
- (startmatch.rm_eo == 0) ? 0 : REG_NOTBOL) ==
180
- /* Translate the end match to be relative to the
181
- * beginning of the line. */
182
- endmatch.rm_so += startmatch.rm_eo;
183
- endmatch.rm_eo += startmatch.rm_eo;
184
- /* There is an end on this line. But does it
185
- * appear on this page, and is the match more
186
- * than zero characters long? */
187
- if (endmatch.rm_eo > startpos &&
188
+ if (regexec(tmpcolor->end, fileptr->data +
189
+ startmatch.rm_eo, 1, &endmatch,
190
+ (startmatch.rm_eo == 0) ? 0 :
191
+ REG_NOTBOL) == 0) {
192
+ /* Translate the end match to be relative to
193
+ * the beginning of the line. */
194
+ endmatch.rm_so += startmatch.rm_eo;
195
+ endmatch.rm_eo += startmatch.rm_eo;
196
+ /* There is an end on this line. But does
197
+ * it appear on this page, and is the match
198
+ * more than zero characters long? */
199
+ if (endmatch.rm_eo > startpos &&
200
endmatch.rm_eo > startmatch.rm_so) {
201
- paintlen = actual_x(converted + index,
202
- strnlenpt(fileptr->data,
203
- endmatch.rm_eo) - start - x_start);
204
+ paintlen = actual_x(converted + index,
205
+ strnlenpt(fileptr->data,
206
+ endmatch.rm_eo) - start -
209
- assert(0 <= x_start && x_start < COLS);
210
+ assert(0 <= x_start && x_start < COLS);
212
- mvwaddnstr(edit, line, x_start, converted +
216
- /* There is no end on this line. But we haven't
217
- * yet looked for one on later lines. */
218
- end_line = fileptr->next;
219
+ mvwaddnstr(edit, line, x_start,
220
+ converted + index, paintlen);
223
+ /* There is no end on this line. But we
224
+ * haven't yet looked for one on later
226
+ end_line = fileptr->next;
228
- while (end_line != NULL &&
229
+ while (end_line != NULL &&
230
regexec(tmpcolor->end, end_line->data,
231
0, NULL, 0) == REG_NOMATCH)
232
- end_line = end_line->next;
233
+ end_line = end_line->next;
235
- if (end_line != NULL) {
236
- assert(0 <= x_start && x_start < COLS);
237
+ if (end_line != NULL) {
238
+ assert(0 <= x_start && x_start < COLS);
240
- mvwaddnstr(edit, line, x_start, converted +
242
- /* We painted to the end of the line, so
243
- * don't bother checking any more starts. */
245
+ mvwaddnstr(edit, line, x_start,
246
+ converted + index, -1);
247
+ /* We painted to the end of the line, so
248
+ * don't bother checking any more
253
+ start_col = startmatch.rm_so + 1;
255
- start_col = startmatch.rm_so + 1;