diff --git a/NEWS b/NEWS index bda571b3..37034312 100644 --- a/NEWS +++ b/NEWS @@ -59,6 +59,7 @@ NEWS * [mod_webdav] allow Depth: Infinity lock on file (fixes #2296) * [mod_status] use snprintf() instead of sprintf() * pass buf size to li_tohex() + * use li_[iu]tostrn() instead of li_[iu]tostr() - 1.4.39 - 2016-01-02 * [core] fix memset_s call (fixes #2698) diff --git a/src/buffer.c b/src/buffer.c index 12123d2d..97514357 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -355,10 +355,6 @@ void li_itostrn(char *buf, size_t buf_len, intmax_t val) { memcpy(buf, str, p_buf_end - str); } -void li_itostr(char *buf, intmax_t val) { - li_itostrn(buf, LI_ITOSTRING_LENGTH, val); -} - void li_utostrn(char *buf, size_t buf_len, uintmax_t val) { char p_buf[LI_ITOSTRING_LENGTH]; char* const p_buf_end = p_buf + sizeof(p_buf); @@ -372,10 +368,6 @@ void li_utostrn(char *buf, size_t buf_len, uintmax_t val) { memcpy(buf, str, p_buf_end - str); } -void li_utostr(char *buf, uintmax_t val) { - li_utostrn(buf, LI_ITOSTRING_LENGTH, val); -} - char int2hex(char c) { return hex_chars[(c & 0x0F)]; } diff --git a/src/buffer.h b/src/buffer.h index c2863318..980c5ea5 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -96,9 +96,7 @@ void buffer_append_strftime(buffer *b, const char *format, const struct tm *tm); #define LI_ITOSTRING_LENGTH (2 + (8 * sizeof(intmax_t) * 31 + 99) / 100) void li_itostrn(char *buf, size_t buf_len, intmax_t val); -void li_itostr(char *buf, intmax_t val); /* buf must have at least LI_ITOSTRING_LENGTH bytes */ void li_utostrn(char *buf, size_t buf_len, uintmax_t val); -void li_utostr(char *buf, uintmax_t val); /* buf must have at least LI_ITOSTRING_LENGTH bytes */ /* buf must be (at least) 2*s_len + 1 big. uses lower-case hex letters. */ void li_tohex(char *buf, size_t buf_len, const char *s, size_t s_len); diff --git a/src/http_auth.c b/src/http_auth.c index 00a2e2b8..54a6ec2e 100644 --- a/src/http_auth.c +++ b/src/http_auth.c @@ -1104,10 +1104,10 @@ int http_auth_digest_generate_nonce(server *srv, mod_auth_plugin_data *p, buffer li_MD5_Update(&Md5Ctx, CONST_STR_LEN("+")); /* we assume sizeof(time_t) == 4 here, but if not it ain't a problem at all */ - li_itostr(hh, srv->cur_ts); + li_itostrn(hh, sizeof(hh), srv->cur_ts); li_MD5_Update(&Md5Ctx, (unsigned char *)hh, strlen(hh)); li_MD5_Update(&Md5Ctx, (unsigned char *)srv->entropy, sizeof(srv->entropy)); - li_itostr(hh, rand()); + li_itostrn(hh, sizeof(hh), rand()); li_MD5_Update(&Md5Ctx, (unsigned char *)hh, strlen(hh)); li_MD5_Final(h, &Md5Ctx); diff --git a/src/mod_cgi.c b/src/mod_cgi.c index 26de4f1d..19434ee8 100644 --- a/src/mod_cgi.c +++ b/src/mod_cgi.c @@ -911,7 +911,7 @@ static int cgi_create_env(server *srv, connection *con, plugin_data *p, buffer * force_assert(s); cgi_env_add(&env, CONST_STR_LEN("SERVER_PROTOCOL"), s, strlen(s)); - li_utostr(buf, + li_utostrn(buf, sizeof(buf), #ifdef HAVE_IPV6 ntohs(srv_sock->addr.plain.sa_family == AF_INET6 ? srv_sock->addr.ipv6.sin6_port : srv_sock->addr.ipv4.sin_port) #else @@ -988,7 +988,7 @@ static int cgi_create_env(server *srv, connection *con, plugin_data *p, buffer * force_assert(s); cgi_env_add(&env, CONST_STR_LEN("REMOTE_ADDR"), s, strlen(s)); - li_utostr(buf, + li_utostrn(buf, sizeof(buf), #ifdef HAVE_IPV6 ntohs(con->dst_addr.plain.sa_family == AF_INET6 ? con->dst_addr.ipv6.sin6_port : con->dst_addr.ipv4.sin_port) #else @@ -1001,7 +1001,7 @@ static int cgi_create_env(server *srv, connection *con, plugin_data *p, buffer * cgi_env_add(&env, CONST_STR_LEN("HTTPS"), CONST_STR_LEN("on")); } - li_itostr(buf, con->request.content_length); + li_itostrn(buf, sizeof(buf), con->request.content_length); cgi_env_add(&env, CONST_STR_LEN("CONTENT_LENGTH"), buf, strlen(buf)); cgi_env_add(&env, CONST_STR_LEN("SCRIPT_FILENAME"), CONST_BUF_LEN(con->physical.path)); cgi_env_add(&env, CONST_STR_LEN("SCRIPT_NAME"), CONST_BUF_LEN(con->uri.path)); diff --git a/src/mod_dirlisting.c b/src/mod_dirlisting.c index 188d4043..717f4e4f 100644 --- a/src/mod_dirlisting.c +++ b/src/mod_dirlisting.c @@ -465,7 +465,7 @@ static int http_list_directory_sizefmt(char *buf, off_t size) { u++; } - li_itostr(out, size); + li_itostrn(out, 4, size); out += strlen(out); out[0] = '.'; out[1] = remain + '0'; diff --git a/src/mod_fastcgi.c b/src/mod_fastcgi.c index e55c06d4..a568e2a5 100644 --- a/src/mod_fastcgi.c +++ b/src/mod_fastcgi.c @@ -1871,7 +1871,7 @@ static int fcgi_create_env(server *srv, handler_ctx *hctx, size_t request_id) { FCGI_ENV_ADD_CHECK(fcgi_env_add(p->fcgi_env, CONST_STR_LEN("GATEWAY_INTERFACE"), CONST_STR_LEN("CGI/1.1")),con) - li_utostr(buf, + li_utostrn(buf, sizeof(buf), #ifdef HAVE_IPV6 ntohs(srv_sock->addr.plain.sa_family ? srv_sock->addr.ipv6.sin6_port : srv_sock->addr.ipv4.sin_port) #else @@ -1891,7 +1891,7 @@ static int fcgi_create_env(server *srv, handler_ctx *hctx, size_t request_id) { } FCGI_ENV_ADD_CHECK(fcgi_env_add(p->fcgi_env, CONST_STR_LEN("SERVER_ADDR"), s, strlen(s)),con) - li_utostr(buf, + li_utostrn(buf, sizeof(buf), #ifdef HAVE_IPV6 ntohs(con->dst_addr.plain.sa_family ? con->dst_addr.ipv6.sin6_port : con->dst_addr.ipv4.sin_port) #else @@ -1907,7 +1907,7 @@ static int fcgi_create_env(server *srv, handler_ctx *hctx, size_t request_id) { if (con->request.content_length > 0 && host->mode != FCGI_AUTHORIZER) { /* CGI-SPEC 6.1.2 and FastCGI spec 6.3 */ - li_itostr(buf, con->request.content_length); + li_itostrn(buf, sizeof(buf), con->request.content_length); FCGI_ENV_ADD_CHECK(fcgi_env_add(p->fcgi_env, CONST_STR_LEN("CONTENT_LENGTH"), buf, strlen(buf)),con) } diff --git a/src/mod_scgi.c b/src/mod_scgi.c index 02c463cd..c1996cf8 100644 --- a/src/mod_scgi.c +++ b/src/mod_scgi.c @@ -1480,7 +1480,7 @@ static int scgi_create_env(server *srv, handler_ctx *hctx) { /* CGI-SPEC 6.1.2, FastCGI spec 6.3 and SCGI spec */ - li_itostr(buf, con->request.content_length); + li_itostrn(buf, sizeof(buf), con->request.content_length); scgi_env_add(p->scgi_env, CONST_STR_LEN("CONTENT_LENGTH"), buf, strlen(buf)); scgi_env_add(p->scgi_env, CONST_STR_LEN("SCGI"), CONST_STR_LEN("1")); @@ -1519,7 +1519,7 @@ static int scgi_create_env(server *srv, handler_ctx *hctx) { scgi_env_add(p->scgi_env, CONST_STR_LEN("GATEWAY_INTERFACE"), CONST_STR_LEN("CGI/1.1")); - li_utostr(buf, + li_utostrn(buf, sizeof(buf), #ifdef HAVE_IPV6 ntohs(srv_sock->addr.plain.sa_family ? srv_sock->addr.ipv6.sin6_port : srv_sock->addr.ipv4.sin_port) #else @@ -1539,7 +1539,7 @@ static int scgi_create_env(server *srv, handler_ctx *hctx) { } scgi_env_add(p->scgi_env, CONST_STR_LEN("SERVER_ADDR"), s, strlen(s)); - li_utostr(buf, + li_utostrn(buf, sizeof(buf), #ifdef HAVE_IPV6 ntohs(con->dst_addr.plain.sa_family ? con->dst_addr.ipv6.sin6_port : con->dst_addr.ipv4.sin_port) #else diff --git a/src/mod_ssi.c b/src/mod_ssi.c index 14433993..16f1e1b7 100644 --- a/src/mod_ssi.c +++ b/src/mod_ssi.c @@ -232,7 +232,7 @@ static int build_ssi_cgi_vars(server *srv, connection *con, plugin_data *p) { ); ssi_env_add(p->ssi_cgi_env, CONST_STRING("GATEWAY_INTERFACE"), "CGI/1.1"); - li_utostr(buf, + li_utostrn(buf, sizeof(buf), #ifdef HAVE_IPV6 ntohs(srv_sock->addr.plain.sa_family ? srv_sock->addr.ipv6.sin6_port : srv_sock->addr.ipv4.sin_port) #else @@ -248,7 +248,7 @@ static int build_ssi_cgi_vars(server *srv, connection *con, plugin_data *p) { if (con->request.content_length > 0) { /* CGI-SPEC 6.1.2 and FastCGI spec 6.3 */ - li_itostr(buf, con->request.content_length); + li_itostrn(buf, sizeof(buf), con->request.content_length); ssi_env_add(p->ssi_cgi_env, CONST_STRING("CONTENT_LENGTH"), buf); } diff --git a/src/mod_usertrack.c b/src/mod_usertrack.c index b65d9001..07e552b0 100644 --- a/src/mod_usertrack.c +++ b/src/mod_usertrack.c @@ -228,10 +228,10 @@ URIHANDLER_FUNC(mod_usertrack_uri_handler) { li_MD5_Update(&Md5Ctx, CONST_STR_LEN("+")); /* we assume sizeof(time_t) == 4 here, but if not it ain't a problem at all */ - li_itostr(hh, srv->cur_ts); + li_itostrn(hh, sizeof(hh), srv->cur_ts); li_MD5_Update(&Md5Ctx, (unsigned char *)hh, strlen(hh)); li_MD5_Update(&Md5Ctx, (unsigned char *)srv->entropy, sizeof(srv->entropy)); - li_itostr(hh, rand()); + li_itostrn(hh, sizeof(hh), rand()); li_MD5_Update(&Md5Ctx, (unsigned char *)hh, strlen(hh)); li_MD5_Final(h, &Md5Ctx);