diff options
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | coreutils/sort.c | 20 | ||||
| -rw-r--r-- | networking/ftpd.c | 17 | ||||
| -rw-r--r-- | networking/httpd.c | 25 | ||||
| -rwxr-xr-x | scripts/trylink | 59 | ||||
| -rwxr-xr-x | testsuite/sort.tests | 36 |
6 files changed, 122 insertions, 37 deletions
| @@ -1,6 +1,6 @@ | |||
| 1 | VERSION = 1 | 1 | VERSION = 1 |
| 2 | PATCHLEVEL = 24 | 2 | PATCHLEVEL = 24 |
| 3 | SUBLEVEL = 0 | 3 | SUBLEVEL = 1 |
| 4 | EXTRAVERSION = | 4 | EXTRAVERSION = |
| 5 | NAME = Unnamed | 5 | NAME = 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 | ||
| 107 | static char *get_key(char *str, struct sort_key *key, int flags) | 107 | static 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 | ||
| 48 | check_cc() { | 48 | check_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 | ||
| 60 | check_libc_is_glibc() { | 63 | check_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 | ||
| 77 | EXE="$1" | 79 | EXE="$1" |
| @@ -83,32 +85,41 @@ A_FILES="$6" | |||
| 83 | LDLIBS="$7" | 85 | LDLIBS="$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 |
| 86 | SORT_SECTION=`check_cc "-Wl,--sort-section,alignment" ""` | 88 | SORT_SECTION="-Wl,--sort-section,alignment" |
| 89 | if ! check_cc "-Wl,--sort-section,alignment"; then | ||
| 90 | echo "Your linker does not support --sort-section,alignment" | ||
| 91 | SORT_SECTION="" | ||
| 92 | fi | ||
| 87 | 93 | ||
| 88 | START_GROUP="-Wl,--start-group" | 94 | START_GROUP="-Wl,--start-group" |
| 89 | END_GROUP="-Wl,--end-group" | 95 | END_GROUP="-Wl,--end-group" |
| 90 | INFO_OPTS="-Wl,--warn-common -Wl,-Map,$EXE.map -Wl,--verbose" | 96 | INFO_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) |
| 93 | SORT_COMMON=`check_cc "-Wl,--sort-common" ""` | 99 | SORT_COMMON="-Wl,--sort-common" |
| 100 | if ! check_cc "-Wl,--sort-common"; then | ||
| 101 | echo "Your linker does not support --sort-common" | ||
| 102 | SORT_COMMON="" | ||
| 103 | fi | ||
| 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. |
| 100 | GC_SECTIONS=`( | 110 | GC_SECTIONS="-Wl,--gc-sections" |
| 101 | . ./.config | 111 | if (. ./.config && test x"$CONFIG_STATIC" = x"y") then |
| 102 | if 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" |
| 104 | else | 114 | # GC_SECTIONS="" |
| 105 | echo "-Wl,--gc-sections" | 115 | fi |
| 106 | fi | 116 | fi |
| 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 |
| 110 | if test -n "$GC_SECTIONS"; then | 118 | if 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 | ||
| 112 | fi | 123 | fi |
| 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 | |||
| 106 | a:b | 106 | a:b |
| 107 | " "" | 107 | " "" |
| 108 | 108 | ||
| 109 | testing "glibc build sort" "sort -t. -k 1,1 -k 2n,2n -k 3 input" "\ | ||
| 110 | GLIBC_2.1 | ||
| 111 | GLIBC_2.1.1 | ||
| 112 | GLIBC_2.2 | ||
| 113 | GLIBC_2.2.1 | ||
| 114 | GLIBC_2.10 | ||
| 115 | GLIBC_2.20 | ||
| 116 | GLIBC_2.21 | ||
| 117 | " "\ | ||
| 118 | GLIBC_2.21 | ||
| 119 | GLIBC_2.1.1 | ||
| 120 | GLIBC_2.2.1 | ||
| 121 | GLIBC_2.2 | ||
| 122 | GLIBC_2.20 | ||
| 123 | GLIBC_2.10 | ||
| 124 | GLIBC_2.1 | ||
| 125 | " "" | ||
| 126 | |||
| 127 | testing "glibc build sort unique" "sort -u -t. -k 1,1 -k 2n,2n -k 3 input" "\ | ||
| 128 | GLIBC_2.1 | ||
| 129 | GLIBC_2.1.1 | ||
| 130 | GLIBC_2.2 | ||
| 131 | GLIBC_2.2.1 | ||
| 132 | GLIBC_2.10 | ||
| 133 | GLIBC_2.20 | ||
| 134 | GLIBC_2.21 | ||
| 135 | " "\ | ||
| 136 | GLIBC_2.10 | ||
| 137 | GLIBC_2.2.1 | ||
| 138 | GLIBC_2.1.1 | ||
| 139 | GLIBC_2.20 | ||
| 140 | GLIBC_2.2 | ||
| 141 | GLIBC_2.1 | ||
| 142 | GLIBC_2.21 | ||
| 143 | " "" | ||
| 144 | |||
| 109 | testing "sort -u should consider field only when discarding" "sort -u -k2 input" "\ | 145 | testing "sort -u should consider field only when discarding" "sort -u -k2 input" "\ |
| 110 | a c | 146 | a c |
| 111 | " "\ | 147 | " "\ |
