Package: busybox / 1:1.22.0-9+deb8u1

1.22.1.diff Patch series | download
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
Subject: upstream changes between 1.22.0 and 1.22.1 (stable branch)

diff --git a/Makefile b/Makefile
index 48d22e2..33d59e3 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
 VERSION = 1
 PATCHLEVEL = 22
-SUBLEVEL = 0
+SUBLEVEL = 1
 EXTRAVERSION =
 NAME = Unnamed
 
diff --git a/findutils/find.c b/findutils/find.c
index 53d8239..5d5e24b 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -1291,9 +1291,27 @@ int find_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int find_main(int argc UNUSED_PARAM, char **argv)
 {
 	int i, firstopt, status = EXIT_SUCCESS;
+	char **past_HLP, *saved;
 
 	INIT_G();
 
+	/* "find -type f" + getopt("+HLP") => disaster.
+	 * Need to avoid getopt running into a non-HLP option.
+	 * Do this by temporarily storing NULL there:
+	 */
+	past_HLP = argv;
+	for (;;) {
+		saved = *++past_HLP;
+		if (!saved)
+			break;
+		if (saved[0] != '-')
+			break;
+		if (!saved[1])
+			break; /* it is "-" */
+		if ((saved+1)[strspn(saved+1, "HLP")] != '\0')
+			break;
+	}
+	*past_HLP = NULL;
 	/* "+": stop on first non-option */
 	i = getopt32(argv, "+HLP");
 	if (i & (1<<0))
@@ -1301,7 +1319,8 @@ int find_main(int argc UNUSED_PARAM, char **argv)
 	if (i & (1<<1))
 		G.recurse_flags |= ACTION_FOLLOWLINKS | ACTION_DANGLING_OK;
 	/* -P is default and is ignored */
-	argv += optind;
+	argv = past_HLP; /* same result as "argv += optind;" */
+	*past_HLP = saved;
 
 	for (firstopt = 0; argv[firstopt]; firstopt++) {
 		if (argv[firstopt][0] == '-')
diff --git a/findutils/grep.c b/findutils/grep.c
index b8ad1bf..a7bc4ca 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -373,6 +373,9 @@ static int grep_file(FILE *file)
  opt_f_not_found: ;
 				}
 			} else {
+#if ENABLE_EXTRA_COMPAT
+				unsigned start_pos;
+#endif
 				char *match_at;
 
 				if (!(gl->flg_mem_alocated_compiled & COMPILED)) {
@@ -389,15 +392,18 @@ static int grep_file(FILE *file)
 #if !ENABLE_EXTRA_COMPAT
 				gl->matched_range.rm_so = 0;
 				gl->matched_range.rm_eo = 0;
+#else
+				start_pos = 0;
 #endif
 				match_at = line;
  opt_w_again:
+//bb_error_msg("'%s' start_pos:%d line_len:%d", match_at, start_pos, line_len);
 				if (
 #if !ENABLE_EXTRA_COMPAT
 					regexec(&gl->compiled_regex, match_at, 1, &gl->matched_range, 0) == 0
 #else
 					re_search(&gl->compiled_regex, match_at, line_len,
-							/*start:*/ 0, /*range:*/ line_len,
+							start_pos, /*range:*/ line_len,
 							&gl->matched_range) >= 0
 #endif
 				) {
@@ -416,8 +422,24 @@ static int grep_file(FILE *file)
 							if (!c || (!isalnum(c) && c != '_')) {
 								found = 1;
 							} else {
-								match_at += gl->matched_range.rm_eo;
-								goto opt_w_again;
+			/*
+			 * Why check gl->matched_range.rm_eo?
+			 * Zero-length match makes -w skip the line:
+			 * "echo foo | grep ^" prints "foo",
+			 * "echo foo | grep -w ^" prints nothing.
+			 * Without such check, we can loop forever.
+			 */
+#if !ENABLE_EXTRA_COMPAT
+								if (gl->matched_range.rm_eo != 0) {
+									match_at += gl->matched_range.rm_eo;
+									goto opt_w_again;
+								}
+#else
+								if (gl->matched_range.rm_eo > start_pos) {
+									start_pos = gl->matched_range.rm_eo;
+									goto opt_w_again;
+								}
+#endif
 							}
 						}
 					}
diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index b168f1b..8564307 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
@@ -1255,7 +1255,9 @@ line_input_t* FAST_FUNC new_line_input_t(int flags)
 {
 	line_input_t *n = xzalloc(sizeof(*n));
 	n->flags = flags;
+#if MAX_HISTORY > 0
 	n->max_history = MAX_HISTORY;
+#endif
 	return n;
 }
 
diff --git a/networking/ntpd.c b/networking/ntpd.c
index ed83415..c4b0187 100644
--- a/networking/ntpd.c
+++ b/networking/ntpd.c
@@ -1445,6 +1445,8 @@ update_local_clock(peer_t *p)
 
 		run_script("step", offset);
 
+		recv_time += offset;
+
 #if USING_INITIAL_FREQ_ESTIMATION
 		if (G.discipline_state == STATE_NSET) {
 			set_new_values(STATE_FREQ, /*offset:*/ 0, recv_time);
diff --git a/testsuite/grep.tests b/testsuite/grep.tests
index 64d99a9..412efff 100755
--- a/testsuite/grep.tests
+++ b/testsuite/grep.tests
@@ -147,6 +147,18 @@ testing "grep -w doesn't stop on 1st mismatch" \
 	"foop foo\n" \
 	""
 
+testing "grep -w ^str doesn't match str not at the beginning" \
+	"grep -w ^str input" \
+	"" \
+	"strstr\n" \
+	""
+
+testing "grep -w ^ doesn't hang" \
+	"grep -w ^ input" \
+	"" \
+	"anything\n" \
+	""
+
 # testing "test name" "commands" "expected result" "file input" "stdin"
 #   file input will be file called "input"
 #   test can create a file "actual" instead of writing to stdout