net/climm: avoid using printf %n; from deraadt

This commit is contained in:
tb 2021-09-20 15:47:12 +00:00
parent 57a42a1bca
commit 39df341be4
4 changed files with 109 additions and 2 deletions

View File

@ -1,9 +1,9 @@
# $OpenBSD: Makefile,v 1.6 2019/07/12 20:48:24 sthen Exp $
# $OpenBSD: Makefile,v 1.7 2021/09/20 15:47:12 tb Exp $
COMMENT = simple, command-line multi messenger
DISTNAME = climm-0.7.1
REVISION = 2
REVISION = 3
CATEGORIES = net

View File

@ -0,0 +1,13 @@
$OpenBSD: patch-include_util_str_h,v 1.1 2021/09/20 15:47:12 tb Exp $
Index: include/util_str.h
--- include/util_str.h.orig
+++ include/util_str.h
@@ -36,6 +36,7 @@ str_t s_deln (str_t str, size_t pos, size_t l
void s_done (str_t str);
const char *s_sprintf (const char *fmt, ...) __attribute__ ((format (__printf__, 1, 2)));
+const char *s_sprintf_len (int *len, 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);

View File

@ -0,0 +1,46 @@
$OpenBSD: patch-src_io_io_socks5_c,v 1.1 2021/09/20 15:47:12 tb Exp $
Index: src/io/io_socks5.c
--- src/io/io_socks5.c.orig
+++ src/io/io_socks5.c
@@ -178,7 +178,7 @@ static io_err_t io_socks5_connecting (Connection *conn
if (!socks5name || !socks5pass)
return io_socks5_seterr (d, IO_RW, i18n (1599, "[SOCKS] Authentication method incorrect"));
- send = s_sprintf ("%c%c%s%c%s%n", 1, (char) strlen (socks5name), socks5name, (char) strlen (socks5pass), socks5pass, &len);
+ send = s_sprintf_len (&len, "%c%c%s%c%s", 1, (char) strlen (socks5name), socks5name, (char) strlen (socks5pass), socks5pass);
e = io_util_write (conn, d->next, send, len);
d->flags = FLAG_CRED_SENT;
d->read = 0;
@@ -231,24 +231,24 @@ static io_err_t io_socks5_connecting (Connection *conn
if (d->funcs->f_accept)
{
if (d->flags == FLAG_SEND_REQ)
- 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);
+ 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));
else
{
- 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);
+ 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);
d->flags = FLAG_REQ_NOPORT_SENT;
}
}
else
{
if (conn->server)
- send = s_sprintf ("%c%c%c%c%c%s%c%c%n", 5, 1, 0, 3,
+ send = s_sprintf_len (&len, "%c%c%c%c%c%s%c%c", 5, 1, 0, 3,
(char)strlen (conn->server), conn->server,
- (char)(conn->port >> 8), (char)(conn->port & 255), &len);
+ (char)(conn->port >> 8), (char)(conn->port & 255));
else
- send = s_sprintf ("%c%c%c%c%c%c%c%c%c%c%n", 5, 1, 0, 1,
+ send = s_sprintf_len (&len, "%c%c%c%c%c%c%c%c%c%c", 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), &len);
+ (char)(conn->port >> 8), (char)(conn->port & 255));
}
e = io_util_write (conn, d->next, send, len);
d->read = 0;

View File

@ -0,0 +1,48 @@
$OpenBSD: patch-src_util_str_c,v 1.1 2021/09/20 15:47:12 tb Exp $
Index: src/util_str.c
--- src/util_str.c.orig
+++ src/util_str.c
@@ -303,6 +303,42 @@ const char *s_sprintf (const char *fmt, ...)
}
/*
+ * 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)