diff options
Diffstat (limited to 'main/libc0.9.32/fixit.patch')
-rw-r--r-- | main/libc0.9.32/fixit.patch | 214 |
1 files changed, 214 insertions, 0 deletions
diff --git a/main/libc0.9.32/fixit.patch b/main/libc0.9.32/fixit.patch new file mode 100644 index 0000000000..faa1bd08f8 --- /dev/null +++ b/main/libc0.9.32/fixit.patch @@ -0,0 +1,214 @@ +diff --git a/libc/inet/getservice.c b/libc/inet/getservice.c +index 03f5c29..47d26a2 100644 +--- a/libc/inet/getservice.c ++++ b/libc/inet/getservice.c +@@ -35,6 +35,7 @@ __UCLIBC_MUTEX_STATIC(mylock, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP); + static parser_t *servp = NULL; + static struct servent serve; + static char *servbuf = NULL; ++static size_t servbuf_sz = SBUFSIZE; + static smallint serv_stayopen; + + void setservent(int stayopen) +@@ -64,11 +65,11 @@ libc_hidden_def(endservent) + int getservent_r(struct servent *result_buf, + char *buf, size_t buflen, struct servent **result) + { +- char **alias, *cp = NULL; ++ char **alias; + char **serv_aliases; + char **tok = NULL; + const size_t aliaslen = sizeof(*serv_aliases) * MAXALIASES; +- int ret = ERANGE; ++ int ret = ENOENT; + + *result = NULL; + if (buflen < aliaslen +@@ -76,31 +77,24 @@ int getservent_r(struct servent *result_buf, + goto DONE_NOUNLOCK; + + __UCLIBC_MUTEX_LOCK(mylock); +- ret = ENOENT; ++ + if (servp == NULL) + setservent(serv_stayopen); + if (servp == NULL) + goto DONE; ++ + servp->data = buf; + servp->data_len = aliaslen; + servp->line_len = buflen - aliaslen; + /* <name>[[:space:]]<port>/<proto>[[:space:]][<aliases>] */ +- if (!config_read(servp, &tok, 4, 3, "# \t/", PARSE_NORMAL)) { ++ if (!config_read(servp, &tok, MAXALIASES, 3, "# \t/", PARSE_NORMAL)) { ++ ret = ERANGE; + goto DONE; + } + result_buf->s_name = *(tok++); + result_buf->s_port = htons((u_short) atoi(*(tok++))); + result_buf->s_proto = *(tok++); + result_buf->s_aliases = alias = serv_aliases = tok; +- cp = *alias; +- while (cp && *cp) { +- if (alias < &serv_aliases[MAXALIASES - 1]) +- *alias++ = cp; +- cp = strpbrk(cp, " \t"); +- if (cp != NULL) +- *cp++ = '\0'; +- } +- *alias = NULL; + *result = result_buf; + ret = 0; + DONE: +@@ -113,19 +107,20 @@ libc_hidden_def(getservent_r) + + static void __initbuf(void) + { +- if (!servbuf) { +- servbuf = malloc(SBUFSIZE); +- if (!servbuf) +- abort(); +- } ++ if (servbuf) ++ servbuf_sz += BUFSZ; ++ servbuf = realloc(servbuf, servbuf_sz); ++ if (!servbuf) ++ abort(); + } + + struct servent *getservent(void) + { + struct servent *result; + +- __initbuf(); +- getservent_r(&serve, servbuf, SBUFSIZE, &result); ++ do { ++ __initbuf(); ++ } while (getservent_r(&serve, servbuf, servbuf_sz, &result) == ERANGE); + return result; + } + +@@ -160,8 +155,10 @@ struct servent *getservbyname(const char *name, const char *proto) + { + struct servent *result; + +- __initbuf(); +- getservbyname_r(name, proto, &serve, servbuf, SBUFSIZE, &result); ++ do { ++ __initbuf(); ++ } while (getservbyname_r(name, proto, &serve, servbuf, servbuf_sz, &result) ++ == ERANGE); + return result; + } + +@@ -191,8 +188,10 @@ struct servent *getservbyport(int port, const char *proto) + { + struct servent *result; + +- __initbuf(); +- getservbyport_r(port, proto, &serve, servbuf, SBUFSIZE, &result); ++ do { ++ __initbuf(); ++ } while (getservbyport_r(port, proto, &serve, servbuf, servbuf_sz, &result) ++ == ERANGE); + return result; + } + libc_hidden_def(getservbyport) +diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c +index d45e5f8..831f521 100644 +--- a/libc/inet/resolv.c ++++ b/libc/inet/resolv.c +@@ -1597,7 +1597,7 @@ int attribute_hidden __read_etc_hosts_r( + struct hostent **result, + int *h_errnop) + { +- char **alias, *cp = NULL; ++ char **alias; + char **host_aliases; + char **tok = NULL; + struct in_addr *h_addr0 = NULL; +@@ -1632,33 +1632,24 @@ int attribute_hidden __read_etc_hosts_r( + parser->line_len = buflen - aliaslen; + *h_errnop = HOST_NOT_FOUND; + /* <ip>[[:space:]][<aliases>] */ +- while (config_read(parser, &tok, 2, 2, "# \t", PARSE_NORMAL)) { ++ while (config_read(parser, &tok, MAXALIASES, 2, "# \t", PARSE_NORMAL)) { + result_buf->h_aliases = alias = host_aliases = tok+1; +- cp = *alias; +- while (cp && *cp) { +- if (alias < &host_aliases[MAXALIASES - 1]) +- *alias++ = cp; +- cp = strpbrk(cp, " \t"); +- if (cp != NULL) +- *cp++ = '\0'; +- } +- *alias = NULL; + if (action == GETHOSTENT) { + /* Return whatever the next entry happens to be. */ + break; + } +- result_buf->h_name = *(result_buf->h_aliases++); + if (action == GET_HOSTS_BYADDR) { +- if (strcmp(name, result_buf->h_name) != 0) ++ if (strcmp(name, *tok) != 0) + continue; + } else { /* GET_HOSTS_BYNAME */ +- alias = result_buf->h_aliases; +- while ((cp = *(alias++))) +- if (strcasecmp(name, cp) == 0) ++ while (*alias) { ++ if (strcasecmp(name, *(alias++)) == 0) + goto found; ++ } + continue; + } + found: ++ result_buf->h_name = *(result_buf->h_aliases++); + result_buf->h_addr_list = (char**)(buf + ALIASOFF); + *(result_buf->h_addr_list + 1) = '\0'; + h_addr0 = (struct in_addr*)(buf + ALIASOFF + 2 * sizeof (char*)); +diff --git a/libc/misc/internals/parse_config.c b/libc/misc/internals/parse_config.c +index 9ddf3ee..e38025f 100644 +--- a/libc/misc/internals/parse_config.c ++++ b/libc/misc/internals/parse_config.c +@@ -73,6 +73,10 @@ static off_t bb_get_chunk_with_continuation(parser_t* parsr) + --pos; + else + break; ++ } else if (parsr->allocated) { ++ parsr->line_len += PAGE_SIZE; ++ parsr->data = realloc(parsr->data, ++ parsr->data_len + parsr->line_len); + } + } + return pos; +@@ -109,9 +113,8 @@ static __always_inline parser_t * FAST_FUNC config_open2(const char *filename, + fp = fopen_func(filename, "r"); + if (!fp) + return NULL; +- parser = malloc(sizeof(*parser)); ++ parser = calloc(1, sizeof(*parser)); + if (parser) { +- memset(parser, 0, sizeof(*parser)); + parser->fp = fp; + } + return parser; +@@ -179,7 +182,7 @@ int attribute_hidden FAST_FUNC config_read(parser_t *parser, char ***tokens, + again: + if (parser->data == NULL) { + if (parser->line_len == 0) +- parser->line_len = 161; ++ parser->line_len = 81; + if (parser->data_len == 0) + parser->data_len += 1 + ntokens * sizeof(char *); + parser->data = realloc(parser->data, +@@ -201,7 +204,7 @@ again: + return 0; + line = parser->line; + +- /* Skip token in the start of line? */ ++ /* Skip multiple token-delimiters in the start of line? */ + if (flags & PARSE_TRIM) + line += strspn(line, delims + 1); + + |