Christian Weisgerber <naddy@mips.inka.de> wrote:
> This includes the list of remaining ports with %n warnings:
>
> editors/cooledit
> mail/exim
> misc/brltty
> net/climm
climm s_sprintf() is a work of art, like an ochre cave painting of a stick
animal with a stick poking through it.
probably predates the better asprintf API, which returns pointer and length.
this one reallocates memory repeatedly to try to gather enough. then it throws
away the length, which we will need. strlen() cannot be used, because the caller
has printed NUL characters into the string.....
So, create a version of s_sprintf() which returns the length, and use
that.
again, someone take it on?
--- climm-0.7.1/climm-0.7.1/src/io/io_socks5.c Sun Sep 19 17:38:51 2021
+++ climm-0.7.1/climm-0.7.1/src/io/io_socks5.c~ Sat Mar 20 08:13:15 2010
@@ -178,7 +178,7 @@
if (!socks5name || !socks5pass)
return io_socks5_seterr (d, IO_RW, i18n (1599, "[SOCKS] Authentication method incorrect"));
- send = s_sprintf_len (&len, "%c%c%s%c%s", 1, (char) strlen (socks5name), socks5name, (char) strlen (socks5pass), socks5pass);
+ send = s_sprintf ("%c%c%s%c%s%n", 1, (char) strlen (socks5name), socks5name, (char) strlen (socks5pass), socks5pass, &len);
e = io_util_write (conn, d->next, send, len);
d->flags = FLAG_CRED_SENT;
d->read = 0;
@@ -231,24 +231,24 @@
if (d->funcs->f_accept)
{
if (d->flags == FLAG_SEND_REQ)
- send = s_sprintf_len (&len, "%c%c%c%c%c%c%c%c%c%c", 5, 2, 0, 1, 0, 0, 0, 0,
- (char)(conn->port >> 8), (char)(conn->port & 255));
+ send = s_sprintf ("%c%c%c%c%c%c%c%c%c%c%n", 5, 2, 0, 1, 0, 0, 0, 0,
+ (char)(conn->port >> 8), (char)(conn->port & 255), &len);
else
{
- send = s_sprintf_len (&len, "%c%c%c%c%c%c%c%c%c%c", 5, 2, 0, 1, 0, 0, 0, 0, 0, 0);
+ send = s_sprintf ("%c%c%c%c%c%c%c%c%c%c%n", 5, 2, 0, 1, 0, 0, 0, 0, 0, 0, &len);
d->flags = FLAG_REQ_NOPORT_SENT;
}
}
else
{
if (conn->server)
- send = s_sprintf_len (&len, "%c%c%c%c%c%s%c%c", 5, 1, 0, 3,
+ send = s_sprintf ("%c%c%c%c%c%s%c%c%n", 5, 1, 0, 3,
(char)strlen (conn->server), conn->server,
- (char)(conn->port >> 8), (char)(conn->port & 255));
+ (char)(conn->port >> 8), (char)(conn->port & 255), &len);
else
- send = s_sprintf_len (&len, "%c%c%c%c%c%c%c%c%c%c", 5, 1, 0, 1,
+ send = s_sprintf ("%c%c%c%c%c%c%c%c%c%c%n", 5, 1, 0, 1,
(char)(conn->ip >> 24), (char)(conn->ip >> 16), (char)(conn->ip >> 8), (char)conn->ip,
- (char)(conn->port >> 8), (char)(conn->port & 255));
+ (char)(conn->port >> 8), (char)(conn->port & 255), &len);
}
e = io_util_write (conn, d->next, send, len);
d->read = 0;
--- climm-0.7.1/climm-0.7.1/src/util_str.c Sun Sep 19 17:37:33 2021
+++ climm-0.7.1/climm-0.7.1/src/util_str.c~ Sat Mar 20 08:13:15 2010
@@ -303,42 +303,6 @@
}
/*
- * Return a static formatted string and length
- */
-const char *s_sprintf_len (int *lenp, const char *fmt, ...)
-{
- static char *buf = NULL;
- static int size = 0;
- va_list args;
- char *nbuf;
- int rc, nsize;
-
- if (!buf)
- buf = calloc (1, size = 1024);
-
- while (1)
- {
- buf[size - 2] = '\0';
- va_start (args, fmt);
- rc = vsnprintf (buf, size, fmt, args);
- va_end (args);
-
- if (rc >= 0 && rc < size && !buf[size - 2])
- break;
-
- nsize = (rc > 0 ? rc + 5 : size * 2);
- nbuf = malloc (nsize);
- if (!nbuf)
- break;
- free (buf);
- buf = nbuf;
- size = nsize;
- }
- *lenp = rc;
- return buf;
-}
-
-/*
* Return a static string consisting of the given IP.
*/
const char *s_ip (UDWORD ip)
--- climm-0.7.1/climm-0.7.1/include/util_str.h Sun Sep 19 17:40:12 2021
+++ climm-0.7.1/climm-0.7.1/include/util_str.h~ Sun Sep 19 17:36:59 2021
@@ -36,7 +36,7 @@
void s_done (str_t str);
const char *s_sprintf (const char *fmt, ...) __attribute__ ((format (__printf__, 1, 2)));
-const char *s_sprintf_len (int *lenp, const char *fmt, ...) __attribute__ ((format (__printf__, 2, 3)));
+const char *s_sprintf_len (int *lenp; const char *fmt, ...) __attribute__ ((format (__printf__, 2, 3)));
const char *s_ip (UDWORD ip);
const char *s_status (status_t status, UDWORD nativestatus);
const char *s_status_short (status_t status);
No comments:
Post a Comment