aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--coreutils/sort.c20
-rw-r--r--networking/ftpd.c17
-rw-r--r--networking/httpd.c25
-rwxr-xr-xscripts/trylink59
-rwxr-xr-xtestsuite/sort.tests36
6 files changed, 122 insertions, 37 deletions
diff --git a/Makefile b/Makefile
index efb6d46b3..ea9dd3db4 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
1VERSION = 1 1VERSION = 1
2PATCHLEVEL = 24 2PATCHLEVEL = 24
3SUBLEVEL = 0 3SUBLEVEL = 1
4EXTRAVERSION = 4EXTRAVERSION =
5NAME = Unnamed 5NAME = Unnamed
6 6
diff --git a/coreutils/sort.c b/coreutils/sort.c
index 36f02543b..c2e8bb8de 100644
--- a/coreutils/sort.c
+++ b/coreutils/sort.c
@@ -106,7 +106,9 @@ static struct sort_key {
106 106
107static char *get_key(char *str, struct sort_key *key, int flags) 107static char *get_key(char *str, struct sort_key *key, int flags)
108{ 108{
109 int start = 0, end = 0, len, j; 109 int start = start; /* for compiler */
110 int end;
111 int len, j;
110 unsigned i; 112 unsigned i;
111 113
112 /* Special case whole string, so we don't have to make a copy */ 114 /* Special case whole string, so we don't have to make a copy */
@@ -123,12 +125,15 @@ static char *get_key(char *str, struct sort_key *key, int flags)
123 end = len; 125 end = len;
124 /* Loop through fields */ 126 /* Loop through fields */
125 else { 127 else {
128 unsigned char ch = 0;
129
126 end = 0; 130 end = 0;
127 for (i = 1; i < key->range[2*j] + j; i++) { 131 for (i = 1; i < key->range[2*j] + j; i++) {
128 if (key_separator) { 132 if (key_separator) {
129 /* Skip body of key and separator */ 133 /* Skip body of key and separator */
130 while (str[end]) { 134 while ((ch = str[end]) != '\0') {
131 if (str[end++] == key_separator) 135 end++;
136 if (ch == key_separator)
132 break; 137 break;
133 } 138 }
134 } else { 139 } else {
@@ -136,7 +141,7 @@ static char *get_key(char *str, struct sort_key *key, int flags)
136 while (isspace(str[end])) 141 while (isspace(str[end]))
137 end++; 142 end++;
138 /* Skip body of key */ 143 /* Skip body of key */
139 while (str[end]) { 144 while (str[end] != '\0') {
140 if (isspace(str[end])) 145 if (isspace(str[end]))
141 break; 146 break;
142 end++; 147 end++;
@@ -144,8 +149,13 @@ static char *get_key(char *str, struct sort_key *key, int flags)
144 } 149 }
145 } 150 }
146 /* Remove last delim: "abc:def:" => "abc:def" */ 151 /* Remove last delim: "abc:def:" => "abc:def" */
147 if (key_separator && j && end != 0) 152 if (j && ch) {
153 //if (str[end-1] != key_separator)
154 // bb_error_msg(_and_die("BUG! "
155 // "str[start:%d,end:%d]:'%.*s'",
156 // start, end, (int)(end-start), &str[start]);
148 end--; 157 end--;
158 }
149 } 159 }
150 if (!j) start = end; 160 if (!j) start = end;
151 } 161 }
diff --git a/networking/ftpd.c b/networking/ftpd.c
index 7735b7233..8345ae67c 100644
--- a/networking/ftpd.c
+++ b/networking/ftpd.c
@@ -1223,11 +1223,26 @@ int ftpd_main(int argc UNUSED_PARAM, char **argv)
1223#endif 1223#endif
1224 argv += optind; 1224 argv += optind;
1225 if (argv[0]) { 1225 if (argv[0]) {
1226 const char *basedir = argv[0];
1226#if !BB_MMU 1227#if !BB_MMU
1227 G.root_fd = xopen("/", O_RDONLY | O_DIRECTORY); 1228 G.root_fd = xopen("/", O_RDONLY | O_DIRECTORY);
1228 close_on_exec_on(G.root_fd); 1229 close_on_exec_on(G.root_fd);
1229#endif 1230#endif
1230 xchroot(argv[0]); 1231 if (chroot(basedir) == 0)
1232 basedir = "/";
1233#if !BB_MMU
1234 else {
1235 close(G.root_fd);
1236 G.root_fd = -1;
1237 }
1238#endif
1239 /*
1240 * If chroot failed, assume that we aren't root,
1241 * and at least chdir to the specified DIR
1242 * (older versions were dying with error message).
1243 * If chroot worked, move current dir to new "/":
1244 */
1245 xchdir(basedir);
1231 } 1246 }
1232 1247
1233#if ENABLE_FEATURE_FTP_AUTHENTICATION 1248#if ENABLE_FEATURE_FTP_AUTHENTICATION
diff --git a/networking/httpd.c b/networking/httpd.c
index 00169c36d..ed15fd883 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -967,19 +967,30 @@ static void send_headers(int responseNum)
967 } 967 }
968#endif 968#endif
969 if (responseNum == HTTP_MOVED_TEMPORARILY) { 969 if (responseNum == HTTP_MOVED_TEMPORARILY) {
970 len += sprintf(iobuf + len, "Location: %s/%s%s\r\n", 970 /* Responding to "GET /dir" with
971 * "HTTP/1.0 302 Found" "Location: /dir/"
972 * - IOW, asking them to repeat with a slash.
973 * Here, overflow IS possible, can't use sprintf:
974 * mkdir test
975 * python -c 'print("get /test?" + ("x" * 8192))' | busybox httpd -i -h .
976 */
977 len += snprintf(iobuf + len, IOBUF_SIZE-3 - len,
978 "Location: %s/%s%s\r\n",
971 found_moved_temporarily, 979 found_moved_temporarily,
972 (g_query ? "?" : ""), 980 (g_query ? "?" : ""),
973 (g_query ? g_query : "")); 981 (g_query ? g_query : ""));
982 if (len > IOBUF_SIZE-3)
983 len = IOBUF_SIZE-3;
974 } 984 }
975 985
976#if ENABLE_FEATURE_HTTPD_ERROR_PAGES 986#if ENABLE_FEATURE_HTTPD_ERROR_PAGES
977 if (error_page && access(error_page, R_OK) == 0) { 987 if (error_page && access(error_page, R_OK) == 0) {
978 strcat(iobuf, "\r\n"); 988 iobuf[len++] = '\r';
979 len += 2; 989 iobuf[len++] = '\n';
980 990 if (DEBUG) {
981 if (DEBUG) 991 iobuf[len] = '\0';
982 fprintf(stderr, "headers: '%s'\n", iobuf); 992 fprintf(stderr, "headers: '%s'\n", iobuf);
993 }
983 full_write(STDOUT_FILENO, iobuf, len); 994 full_write(STDOUT_FILENO, iobuf, len);
984 if (DEBUG) 995 if (DEBUG)
985 fprintf(stderr, "writing error page: '%s'\n", error_page); 996 fprintf(stderr, "writing error page: '%s'\n", error_page);
@@ -1021,8 +1032,10 @@ static void send_headers(int responseNum)
1021 responseNum, responseString, 1032 responseNum, responseString,
1022 responseNum, responseString, infoString); 1033 responseNum, responseString, infoString);
1023 } 1034 }
1024 if (DEBUG) 1035 if (DEBUG) {
1036 iobuf[len] = '\0';
1025 fprintf(stderr, "headers: '%s'\n", iobuf); 1037 fprintf(stderr, "headers: '%s'\n", iobuf);
1038 }
1026 if (full_write(STDOUT_FILENO, iobuf, len) != len) { 1039 if (full_write(STDOUT_FILENO, iobuf, len) != len) {
1027 if (verbose > 1) 1040 if (verbose > 1)
1028 bb_perror_msg("error"); 1041 bb_perror_msg("error");
diff --git a/scripts/trylink b/scripts/trylink
index 48c487bcd..357aa6277 100755
--- a/scripts/trylink
+++ b/scripts/trylink
@@ -47,18 +47,22 @@ try() {
47 47
48check_cc() { 48check_cc() {
49 local tempname="$(mktemp)" 49 local tempname="$(mktemp)"
50 local r
51 echo "int main(int argc,char**argv){return argv?argc:0;}" >"$tempname".c
50 # Can use "-o /dev/null", but older gcc tend to *unlink it* on failure! :( 52 # Can use "-o /dev/null", but older gcc tend to *unlink it* on failure! :(
51 # "-xc": C language. "/dev/null" is an empty source file. 53 # Was using "-xc /dev/null", but we need a valid C program.
52 if $CC $CPPFLAGS $CFLAGS $1 -shared -xc /dev/null -o "$tempname".o >/dev/null 2>&1; then 54 # "eval" may be needed if CFLAGS can contain
53 echo "$1"; 55 # '... -D"BB_VER=KBUILD_STR(1.N.M)" ...'
54 else 56 # and we need shell to process quotes!
55 echo "$2"; 57 $CC $CFLAGS $1 "$tempname".c -o "$tempname" >/dev/null 2>&1
56 fi 58 r=$?
57 rm -f "$tempname" "$tempname".o 59 rm -f "$tempname" "$tempname".c "$tempname".o
60 return $r
58} 61}
59 62
60check_libc_is_glibc() { 63check_libc_is_glibc() {
61 local tempname="$(mktemp)" 64 local tempname="$(mktemp)"
65 local r
62 echo "\ 66 echo "\
63 #include <stdlib.h> 67 #include <stdlib.h>
64 /* Apparently uclibc defines __GLIBC__ (compat trick?). Oh well. */ 68 /* Apparently uclibc defines __GLIBC__ (compat trick?). Oh well. */
@@ -66,12 +70,10 @@ check_libc_is_glibc() {
66 syntax error here 70 syntax error here
67 #endif 71 #endif
68 " >"$tempname".c 72 " >"$tempname".c
69 if $CC $CPPFLAGS $CFLAGS "$tempname".c -c -o "$tempname".o >/dev/null 2>&1; then 73 ! $CC $CFLAGS "$tempname".c -c -o "$tempname".o >/dev/null 2>&1
70 echo "$2"; 74 r=$?
71 else 75 rm -f "$tempname" "$tempname".c "$tempname".o
72 echo "$1"; 76 return $r
73 fi
74 rm -f "$tempname" "$tempname".[co]
75} 77}
76 78
77EXE="$1" 79EXE="$1"
@@ -83,32 +85,41 @@ A_FILES="$6"
83LDLIBS="$7" 85LDLIBS="$7"
84 86
85# The --sort-section option is not supported by older versions of ld 87# The --sort-section option is not supported by older versions of ld
86SORT_SECTION=`check_cc "-Wl,--sort-section,alignment" ""` 88SORT_SECTION="-Wl,--sort-section,alignment"
89if ! check_cc "-Wl,--sort-section,alignment"; then
90 echo "Your linker does not support --sort-section,alignment"
91 SORT_SECTION=""
92fi
87 93
88START_GROUP="-Wl,--start-group" 94START_GROUP="-Wl,--start-group"
89END_GROUP="-Wl,--end-group" 95END_GROUP="-Wl,--end-group"
90INFO_OPTS="-Wl,--warn-common -Wl,-Map,$EXE.map -Wl,--verbose" 96INFO_OPTS="-Wl,--warn-common -Wl,-Map,$EXE.map -Wl,--verbose"
91 97
92# gold may not support --sort-common (yet) 98# gold may not support --sort-common (yet)
93SORT_COMMON=`check_cc "-Wl,--sort-common" ""` 99SORT_COMMON="-Wl,--sort-common"
100if ! check_cc "-Wl,--sort-common"; then
101 echo "Your linker does not support --sort-common"
102 SORT_COMMON=""
103fi
94 104
95# Static linking against glibc produces buggy executables 105# Static linking against glibc produces buggy executables
96# (glibc does not cope well with ld --gc-sections). 106# (glibc does not cope well with ld --gc-sections).
97# See sources.redhat.com/bugzilla/show_bug.cgi?id=3400 107# See sources.redhat.com/bugzilla/show_bug.cgi?id=3400
98# Note that glibc is unsuitable for static linking anyway. 108# Note that glibc is unsuitable for static linking anyway.
99# We are removing -Wl,--gc-sections from link command line. 109# We are removing -Wl,--gc-sections from link command line.
100GC_SECTIONS=`( 110GC_SECTIONS="-Wl,--gc-sections"
101. ./.config 111if (. ./.config && test x"$CONFIG_STATIC" = x"y") then
102if test x"$CONFIG_STATIC" = x"y"; then 112 if check_libc_is_glibc; then
103 check_libc_is_glibc "" "-Wl,--gc-sections" 113 echo "Static linking against glibc, can't use --gc-sections"
104else 114# GC_SECTIONS=""
105 echo "-Wl,--gc-sections" 115 fi
106fi 116fi
107)`
108
109# The --gc-sections option is not supported by older versions of ld 117# The --gc-sections option is not supported by older versions of ld
110if test -n "$GC_SECTIONS"; then 118if test -n "$GC_SECTIONS"; then
111 GC_SECTIONS=`check_cc "$GC_SECTIONS" ""` 119 if ! check_cc "$GC_SECTIONS"; then
120 echo "Your linker does not support $GC_SECTIONS"
121 GC_SECTIONS=""
122 fi
112fi 123fi
113 124
114# Sanitize lib list (dups, extra spaces etc) 125# Sanitize lib list (dups, extra spaces etc)
diff --git a/testsuite/sort.tests b/testsuite/sort.tests
index c4b223464..39c7af738 100755
--- a/testsuite/sort.tests
+++ b/testsuite/sort.tests
@@ -106,6 +106,42 @@ a/a:a
106a:b 106a:b
107" "" 107" ""
108 108
109testing "glibc build sort" "sort -t. -k 1,1 -k 2n,2n -k 3 input" "\
110GLIBC_2.1
111GLIBC_2.1.1
112GLIBC_2.2
113GLIBC_2.2.1
114GLIBC_2.10
115GLIBC_2.20
116GLIBC_2.21
117" "\
118GLIBC_2.21
119GLIBC_2.1.1
120GLIBC_2.2.1
121GLIBC_2.2
122GLIBC_2.20
123GLIBC_2.10
124GLIBC_2.1
125" ""
126
127testing "glibc build sort unique" "sort -u -t. -k 1,1 -k 2n,2n -k 3 input" "\
128GLIBC_2.1
129GLIBC_2.1.1
130GLIBC_2.2
131GLIBC_2.2.1
132GLIBC_2.10
133GLIBC_2.20
134GLIBC_2.21
135" "\
136GLIBC_2.10
137GLIBC_2.2.1
138GLIBC_2.1.1
139GLIBC_2.20
140GLIBC_2.2
141GLIBC_2.1
142GLIBC_2.21
143" ""
144
109testing "sort -u should consider field only when discarding" "sort -u -k2 input" "\ 145testing "sort -u should consider field only when discarding" "sort -u -k2 input" "\
110a c 146a c
111" "\ 147" "\