Mercurial > irccd
changeset 1079:8f26ee9cc6dd
misc: unconditionnally add BSD->POSIX extensions
author | David Demelier <markand@malikania.fr> |
---|---|
date | Fri, 16 Jul 2021 20:18:29 +0200 |
parents | d0adbcc0768e |
children | 84d567d1c641 |
files | GNUmakefile examples/sample-plugin.c extern/libbsd/reallocarray.c extern/libbsd/strlcat.c extern/libbsd/strlcpy.c irccd/conf.y irccd/dl-plugin.c irccd/js-plugin.c irccd/jsapi-directory.c irccd/jsapi-file.c irccd/jsapi-rule.c irccd/peer.c irccd/transport.c irccdctl/irccdctl.c lib/irccd/channel.c lib/irccd/config.h.in lib/irccd/conn.c lib/irccd/event.c lib/irccd/hook.c lib/irccd/irccd.c lib/irccd/log.c lib/irccd/server.c lib/irccd/subst.c lib/irccd/util.c lib/irccd/util.h plugins/links/links.c tests/data/example-dl-plugin.c |
diffstat | 27 files changed, 202 insertions(+), 91 deletions(-) [+] |
line wrap: on
line diff
--- a/GNUmakefile Thu Jul 15 09:33:33 2021 +0200 +++ b/GNUmakefile Fri Jul 16 20:18:29 2021 +0200 @@ -47,7 +47,10 @@ lib/irccd/rule.c \ lib/irccd/server.c \ lib/irccd/subst.c \ - lib/irccd/util.c + lib/irccd/util.c \ + extern/libbsd/reallocarray.c \ + extern/libbsd/strlcat.c \ + extern/libbsd/strlcpy.c LIB_OBJS= ${LIB_SRCS:.c=.o} LIB_DEPS= ${LIB_SRCS:.c=.d} @@ -146,12 +149,8 @@ # Per system commands. OS:= $(shell uname -s) -ifeq (${OS},Darwin) -LIB_SRCS+= extern/libbsd/reallocarray.c -endif - # Compile flags. -DEFS= -D_BSD_SOURCE -DTOP=\"$(shell pwd)\" -fPIC +DEFS= -DTOP=\"$(shell pwd)\" -fPIC ifeq (${DEBUG},1) CFLAGS+= -O0 -g
--- a/examples/sample-plugin.c Thu Jul 15 09:33:33 2021 +0200 +++ b/examples/sample-plugin.c Fri Jul 16 20:18:29 2021 +0200 @@ -139,9 +139,9 @@ { /* Assuming my_option_* variable exist. */ if (strcmp(key, "level") == 0) - strlcpy(my_option_level, value, sizeof (my_option_level)); + irc_util_strlcpy(my_option_level, value, sizeof (my_option_level)); else if (strcmp(key, "language") == 0) - strlcpy(my_option_language, value, sizeof (my_option_language)); + irc_util_strlcpy(my_option_language, value, sizeof (my_option_language)); } void @@ -149,9 +149,9 @@ { /* Assuming my_template_* variable exist. */ if (strcmp(key, "level") == 0) - strlcpy(my_template_level, value, sizeof (my_template_level)); + irc_util_strlcpy(my_template_level, value, sizeof (my_template_level)); else if (strcmp(key, "language") == 0) - strlcpy(my_template_language, value, sizeof (my_template_language)); + irc_util_strlcpy(my_template_language, value, sizeof (my_template_language)); } /*
--- a/extern/libbsd/reallocarray.c Thu Jul 15 09:33:33 2021 +0200 +++ b/extern/libbsd/reallocarray.c Fri Jul 16 20:18:29 2021 +0200 @@ -27,7 +27,7 @@ #define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4)) void * -reallocarray(void *optr, size_t nmemb, size_t size) +openbsd_reallocarray(void *optr, size_t nmemb, size_t size) { if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && nmemb > 0 && SIZE_MAX / nmemb < size) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extern/libbsd/strlcat.c Fri Jul 16 20:18:29 2021 +0200 @@ -0,0 +1,55 @@ +/* $OpenBSD: strlcat.c,v 1.19 2019/01/25 00:19:25 millert Exp $ */ + +/* + * Copyright (c) 1998, 2015 Todd C. Miller <millert@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/types.h> +#include <string.h> + +/* + * Appends src to string dst of size dsize (unlike strncat, dsize is the + * full size of dst, not space left). At most dsize-1 characters + * will be copied. Always NUL terminates (unless dsize <= strlen(dst)). + * Returns strlen(src) + MIN(dsize, strlen(initial dst)). + * If retval >= dsize, truncation occurred. + */ +size_t +irc_util_strlcat(char *dst, const char *src, size_t dsize) +{ + const char *odst = dst; + const char *osrc = src; + size_t n = dsize; + size_t dlen; + + /* Find the end of dst and adjust bytes left but don't go past end. */ + while (n-- != 0 && *dst != '\0') + dst++; + dlen = dst - odst; + n = dsize - dlen; + + if (n-- == 0) + return(dlen + strlen(src)); + while (*src != '\0') { + if (n != 0) { + *dst++ = *src; + n--; + } + src++; + } + *dst = '\0'; + + return(dlen + (src - osrc)); /* count does not include NUL */ +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extern/libbsd/strlcpy.c Fri Jul 16 20:18:29 2021 +0200 @@ -0,0 +1,50 @@ +/* $OpenBSD: strlcpy.c,v 1.16 2019/01/25 00:19:25 millert Exp $ */ + +/* + * Copyright (c) 1998, 2015 Todd C. Miller <millert@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <sys/types.h> +#include <string.h> + +/* + * Copy string src to buffer dst of size dsize. At most dsize-1 + * chars will be copied. Always NUL terminates (unless dsize == 0). + * Returns strlen(src); if retval >= dsize, truncation occurred. + */ +size_t +irc_util_strlcpy(char *dst, const char *src, size_t dsize) +{ + const char *osrc = src; + size_t nleft = dsize; + + /* Copy as many bytes as will fit. */ + if (nleft != 0) { + while (--nleft != 0) { + if ((*dst++ = *src++) == '\0') + break; + } + } + + /* Not enough room in dst, add NUL and traverse rest of src. */ + if (nleft == 0) { + if (dsize != 0) + *dst = '\0'; /* NUL-terminate dst */ + while (*src++) + ; + } + + return(src - osrc - 1); /* count does not include NUL */ +}
--- a/irccd/conf.y Thu Jul 15 09:33:33 2021 +0200 +++ b/irccd/conf.y Fri Jul 16 20:18:29 2021 +0200 @@ -531,9 +531,9 @@ } if ($4->prefix) - strlcpy(s->prefix, $4->prefix, sizeof (s->prefix)); + irc_util_strlcpy(s->prefix, $4->prefix, sizeof (s->prefix)); if ($4->password) - strlcpy(s->ident.password, $4->password, sizeof (s->ident.password)); + irc_util_strlcpy(s->ident.password, $4->password, sizeof (s->ident.password)); s->flags = $4->flags; irc_bot_server_add(s); @@ -679,7 +679,7 @@ if (!(yyin = fopen(path, "r"))) irc_util_die("%s: %s\n", path, strerror(errno)); - strlcpy(confpath, path, sizeof (confpath)); + irc_util_strlcpy(confpath, path, sizeof (confpath)); yyparse(); fclose(yyin); }
--- a/irccd/dl-plugin.c Thu Jul 15 09:33:33 2021 +0200 +++ b/irccd/dl-plugin.c Fri Jul 16 20:18:29 2021 +0200 @@ -192,7 +192,7 @@ struct stat st; memset(&self, 0, sizeof (self)); - strlcpy(self.plugin.name, name, sizeof (self.plugin.name)); + irc_util_strlcpy(self.plugin.name, name, sizeof (self.plugin.name)); /* * It's not possible to get the exact error code when loading a plugin @@ -211,7 +211,7 @@ } /* Compute prefix name */ - strlcpy(self.prefix, irc_util_basename(path), sizeof (self.prefix)); + irc_util_strlcpy(self.prefix, irc_util_basename(path), sizeof (self.prefix)); /* Remove plugin extension. */ self.prefix[strcspn(self.prefix, ".")] = '\0'; @@ -275,14 +275,14 @@ ldr->open = wrap_open; #if defined(_WIN32) - strlcpy(ldr->extensions, "dll", sizeof (ldr->extensions)); + irc_util_strlcpy(ldr->extensions, "dll", sizeof (ldr->extensions)); #elif defined(__APPLE__) - strlcpy(ldr->extensions, "so:dylib", sizeof (ldr->extensions)); + irc_util_strlcpy(ldr->extensions, "so:dylib", sizeof (ldr->extensions)); #else - strlcpy(ldr->extensions, "so", sizeof (ldr->extensions)); + irc_util_strlcpy(ldr->extensions, "so", sizeof (ldr->extensions)); #endif - strlcpy(ldr->paths, IRCCD_LIBDIR "/irccd", sizeof (ldr->paths)); + irc_util_strlcpy(ldr->paths, IRCCD_LIBDIR "/irccd", sizeof (ldr->paths)); return ldr; }
--- a/irccd/js-plugin.c Thu Jul 15 09:33:33 2021 +0200 +++ b/irccd/js-plugin.c Fri Jul 16 20:18:29 2021 +0200 @@ -477,10 +477,10 @@ js = irc_util_calloc(1, sizeof (*js)); js->ctx = duk_create_heap(wrap_malloc, wrap_realloc, wrap_free, NULL, NULL); - strlcpy(js->plugin.name, name, sizeof (js->plugin.name)); + irc_util_strlcpy(js->plugin.name, name, sizeof (js->plugin.name)); /* Copy path because Duktape has no notions of it. */ - strlcpy(js->location, path, sizeof (js->location)); + irc_util_strlcpy(js->location, path, sizeof (js->location)); /* Tables used to retrieve data. */ duk_push_object(js->ctx); @@ -628,8 +628,8 @@ ldr = irc_util_calloc(1, sizeof (*ldr)); ldr->open = wrap_open; - strlcpy(ldr->extensions, "js", sizeof (ldr->extensions)); - strlcpy(ldr->paths, IRCCD_LIBDIR "/irccd", sizeof (ldr->paths)); + irc_util_strlcpy(ldr->extensions, "js", sizeof (ldr->extensions)); + irc_util_strlcpy(ldr->paths, IRCCD_LIBDIR "/irccd", sizeof (ldr->paths)); return ldr; }
--- a/irccd/jsapi-directory.c Thu Jul 15 09:33:33 2021 +0200 +++ b/irccd/jsapi-directory.c Fri Jul 16 20:18:29 2021 +0200 @@ -30,6 +30,8 @@ #include <duktape.h> +#include <irccd/util.h> + #include "jsapi-system.h" enum { @@ -78,11 +80,11 @@ * Append full path for the given entry. * e.g. /foo/bar/ -> /foo/bar/quux.txt */ - strlcat(cs->path, entry->d_name, sizeof (cs->path)); + irc_util_strlcat(cs->path, entry->d_name, sizeof (cs->path)); /* Go recursively if it's a directory and activated. */ if (S_ISDIR(st.st_mode) && cs->recursive) { - strlcat(cs->path, "/", sizeof (cs->path)); + irc_util_strlcat(cs->path, "/", sizeof (cs->path)); entrylen += 1; @@ -96,7 +98,7 @@ close(childfd); } - strlcpy(cs->entry, entry->d_name, sizeof (cs->entry)); + irc_util_strlcpy(cs->entry, entry->d_name, sizeof (cs->entry)); if (cs->fn(cs)) { ret = 1; @@ -122,9 +124,9 @@ pathlen = strlen(path); - if (strlcpy(cs->path, path, sizeof (cs->path)) >= sizeof (cs->path)) + if (irc_util_strlcpy(cs->path, path, sizeof (cs->path)) >= sizeof (cs->path)) return errno = ENOMEM, -1; - if (cs->path[pathlen - 1] != '/' && strlcat(cs->path, "/", sizeof (cs->path)) >= sizeof (cs->path)) + if (cs->path[pathlen - 1] != '/' && irc_util_strlcat(cs->path, "/", sizeof (cs->path)) >= sizeof (cs->path)) return errno = ENOMEM, -1; ret = recursedir(fd, cs); @@ -354,7 +356,7 @@ char path[PATH_MAX], *p; /* Copy the directory to normalize and iterate over '/'. */ - strlcpy(path, duk_require_string(ctx, 0), sizeof (path)); + irc_util_strlcpy(path, duk_require_string(ctx, 0), sizeof (path)); normalize(path); #if defined(_WIN32)
--- a/irccd/jsapi-file.c Thu Jul 15 09:33:33 2021 +0200 +++ b/irccd/jsapi-file.c Fri Jul 16 20:18:29 2021 +0200 @@ -334,7 +334,7 @@ file = irc_util_calloc(1, sizeof (*file)); file->fp = fp; file->finalizer = fclose; - strlcpy(file->path, path, sizeof (file->path)); + irc_util_strlcpy(file->path, path, sizeof (file->path)); duk_push_this(ctx); duk_push_pointer(ctx, file); @@ -483,7 +483,7 @@ }; if (path) - strlcpy(file.path, path, sizeof (file.path)); + irc_util_strlcpy(file.path, path, sizeof (file.path)); duk_push_object(ctx); duk_push_pointer(ctx, irc_util_memdup(&file, sizeof (file)));
--- a/irccd/jsapi-rule.c Thu Jul 15 09:33:33 2021 +0200 +++ b/irccd/jsapi-rule.c Fri Jul 16 20:18:29 2021 +0200 @@ -23,6 +23,7 @@ #include <irccd/irccd.h> #include <irccd/rule.h> +#include <irccd/util.h> #include "jsapi-rule.h" @@ -32,7 +33,7 @@ char tmp[IRC_RULE_LEN], *token, *p; size_t i = 0; - strlcpy(tmp, value, sizeof (tmp)); + irc_util_strlcpy(tmp, value, sizeof (tmp)); duk_push_array(ctx); for (p = tmp; (token = strtok_r(p, ":", &p)); ) {
--- a/irccd/peer.c Thu Jul 15 09:33:33 2021 +0200 +++ b/irccd/peer.c Fri Jul 16 20:18:29 2021 +0200 @@ -173,7 +173,7 @@ { static char buf[IRC_RULE_LEN]; - strlcpy(buf, value, sizeof (buf)); + irc_util_strlcpy(buf, value, sizeof (buf)); for (char *p = buf; *p; ++p) if (*p == ':') @@ -1048,7 +1048,7 @@ buf[nr] = '\0'; - if (strlcat(p->in, buf, sizeof (p->in)) >= sizeof (p->in)) { + if (irc_util_strlcat(p->in, buf, sizeof (p->in)) >= sizeof (p->in)) { errno = EMSGSIZE; return -1; } @@ -1107,8 +1107,8 @@ if (required + 1 >= avail) return -1; - strlcat(p->out, buf, sizeof (p->out)); - strlcat(p->out, "\n", sizeof (p->out)); + irc_util_strlcat(p->out, buf, sizeof (p->out)); + irc_util_strlcat(p->out, "\n", sizeof (p->out)); return 0; }
--- a/irccd/transport.c Thu Jul 15 09:33:33 2021 +0200 +++ b/irccd/transport.c Fri Jul 16 20:18:29 2021 +0200 @@ -45,9 +45,9 @@ int oldumask; - addr.sun_family = PF_LOCAL; + addr.sun_family = AF_UNIX; - if (strlcpy(addr.sun_path, path, sizeof (addr.sun_path)) >= sizeof (addr.sun_path)) { + if (irc_util_strlcpy(addr.sun_path, path, sizeof (addr.sun_path)) >= sizeof (addr.sun_path)) { errno = ENAMETOOLONG; goto err; } @@ -55,7 +55,7 @@ /* Silently remove the file first. */ unlink(path); - if ((fd = socket(PF_LOCAL, SOCK_STREAM, 0)) < 0) + if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) goto err; /* -ux, -gx, -orwx */
--- a/irccdctl/irccdctl.c Thu Jul 15 09:33:33 2021 +0200 +++ b/irccdctl/irccdctl.c Fri Jul 16 20:18:29 2021 +0200 @@ -56,12 +56,12 @@ if ((nr = recv(sock, buf, sizeof (buf) - 1, 0)) <= 0) irc_util_die("abort: %s\n", strerror(nr == 0 ? ECONNRESET : errno)); - if (strlcat(in, buf, sizeof (in)) >= sizeof (in)) + if (irc_util_strlcat(in, buf, sizeof (in)) >= sizeof (in)) irc_util_die("abort: %s\n", strerror(EMSGSIZE)); } *nl = '\0'; - strlcpy(ret, in, sizeof (ret)); + irc_util_strlcpy(ret, in, sizeof (ret)); memmove(in, nl + 1, sizeof (in) - (nl - in) - 1); return ret; @@ -105,8 +105,8 @@ vsnprintf(buf, sizeof (buf), fmt, ap); va_end(ap); - if (strlcat(out, buf, sizeof (out)) >= sizeof (out) || - strlcat(out, "\n", sizeof (out)) >= sizeof (out)) + if (irc_util_strlcat(out, buf, sizeof (out)) >= sizeof (out) || + irc_util_strlcat(out, "\n", sizeof (out)) >= sizeof (out)) irc_util_die("abort: %s\n", strerror(EMSGSIZE)); while (out[0]) { @@ -980,7 +980,7 @@ for (int ch; (ch = ketopt(&ko, argc, argv, 0, "s:v", NULL)) != -1; ) { switch (ch) { case 's': - strlcpy(sockaddr.sun_path, ko.arg, sizeof (sockaddr.sun_path)); + irc_util_strlcpy(sockaddr.sun_path, ko.arg, sizeof (sockaddr.sun_path)); break; case 'v': verbose = 1;
--- a/lib/irccd/channel.c Thu Jul 15 09:33:33 2021 +0200 +++ b/lib/irccd/channel.c Fri Jul 16 20:18:29 2021 +0200 @@ -35,8 +35,8 @@ ch = irc_util_calloc(1, sizeof (*ch)); ch->joined = joined; - strlcpy(ch->name, name, sizeof (ch->name)); - strlcpy(ch->password, password ? password : "", sizeof (ch->password)); + irc_util_strlcpy(ch->name, name, sizeof (ch->name)); + irc_util_strlcpy(ch->password, password ? password : "", sizeof (ch->password)); return ch; } @@ -54,7 +54,7 @@ user = irc_util_malloc(sizeof (*user)); user->modes = modes; - strlcpy(user->nickname, nickname, sizeof (user->nickname)); + irc_util_strlcpy(user->nickname, nickname, sizeof (user->nickname)); LL_PREPEND(ch->users, user); }
--- a/lib/irccd/config.h.in Thu Jul 15 09:33:33 2021 +0200 +++ b/lib/irccd/config.h.in Fri Jul 16 20:18:29 2021 +0200 @@ -32,12 +32,4 @@ @define WITH_JS@ @define WITH_SSL@ -#if defined(__APPLE__) -# include <stddef.h> - -void * -reallocarray(void *, size_t, size_t); - -#endif - #endif /* !IRCCD_CONFIG_H */
--- a/lib/irccd/conn.c Thu Jul 15 09:33:33 2021 +0200 +++ b/lib/irccd/conn.c Fri Jul 16 20:18:29 2021 +0200 @@ -73,7 +73,7 @@ size_t a; memset(msg, 0, sizeof (*msg)); - strlcpy(msg->buf, line, sizeof (msg->buf)); + irc_util_strlcpy(msg->buf, line, sizeof (msg->buf)); /* * IRC message is defined as following: @@ -538,9 +538,9 @@ assert(conn); assert(data); - if (strlcat(conn->out, data, sizeof (conn->out)) >= sizeof (conn->out)) + if (irc_util_strlcat(conn->out, data, sizeof (conn->out)) >= sizeof (conn->out)) return errno = EMSGSIZE, -1; - if (strlcat(conn->out, "\r\n", sizeof (conn->out)) >= sizeof (conn->out)) + if (irc_util_strlcat(conn->out, "\r\n", sizeof (conn->out)) >= sizeof (conn->out)) return errno = EMSGSIZE, -1; return 0;
--- a/lib/irccd/event.c Thu Jul 15 09:33:33 2021 +0200 +++ b/lib/irccd/event.c Fri Jul 16 20:18:29 2021 +0200 @@ -24,6 +24,7 @@ #include "event.h" #include "server.h" +#include "util.h" int irc_event_str(const struct irc_event *ev, char *str, size_t strsz) @@ -71,7 +72,7 @@ ev->mode.mode); for (char **mode = ev->mode.args; *mode; ++mode) - written = strlcat(str, *mode, strsz); + written = irc_util_strlcat(str, *mode, strsz); break; case IRC_EVENT_NICK:
--- a/lib/irccd/hook.c Thu Jul 15 09:33:33 2021 +0200 +++ b/lib/irccd/hook.c Fri Jul 16 20:18:29 2021 +0200 @@ -137,8 +137,8 @@ struct irc_hook *h; h = irc_util_malloc(sizeof (*h)); - strlcpy(h->name, name, sizeof (h->name)); - strlcpy(h->path, path, sizeof (h->path)); + irc_util_strlcpy(h->name, name, sizeof (h->name)); + irc_util_strlcpy(h->path, path, sizeof (h->path)); return h; }
--- a/lib/irccd/irccd.c Thu Jul 15 09:33:33 2021 +0200 +++ b/lib/irccd/irccd.c Fri Jul 16 20:18:29 2021 +0200 @@ -190,7 +190,7 @@ char path[PATH_MAX], buf[IRC_EXTENSIONS_LEN], *t, *ext; struct irc_plugin *p; - strlcpy(buf, ldr->extensions, sizeof (buf)); + irc_util_strlcpy(buf, ldr->extensions, sizeof (buf)); for (t = buf; (ext = strtok_r(t, ":", &t)); ) { snprintf(path, sizeof (path), "%s/%s.%s", base, name, ext); @@ -237,7 +237,7 @@ { char exts[IRC_EXTENSIONS_LEN], *token, *p, *ext; - strlcpy(exts, ldr->extensions, sizeof (exts)); + irc_util_strlcpy(exts, ldr->extensions, sizeof (exts)); /* If we're unable to find an extension, assume it's allowed. */ if (!(ext = strrchr(path, '.'))) @@ -366,7 +366,7 @@ p = open_plugin(ldr, name, path); } else { /* Copy the paths to tokenize it. */ - strlcpy(buf, ldr->paths, sizeof (buf)); + irc_util_strlcpy(buf, ldr->paths, sizeof (buf)); /* * For every directory (separated by colon) call find_plugin
--- a/lib/irccd/log.c Thu Jul 15 09:33:33 2021 +0200 +++ b/lib/irccd/log.c Fri Jul 16 20:18:29 2021 +0200 @@ -168,7 +168,7 @@ void irc_log_set_template(const char *fmt) { - strlcpy(tmpl, fmt ? fmt : DEFAULT_TEMPLATE, sizeof (tmpl)); + irc_util_strlcpy(tmpl, fmt ? fmt : DEFAULT_TEMPLATE, sizeof (tmpl)); } void
--- a/lib/irccd/server.c Thu Jul 15 09:33:33 2021 +0200 +++ b/lib/irccd/server.c Fri Jul 16 20:18:29 2021 +0200 @@ -91,10 +91,10 @@ ch = irc_util_calloc(1, sizeof (*ch)); ch->joined = joined; - strlcpy(ch->name, name, sizeof (ch->name)); + irc_util_strlcpy(ch->name, name, sizeof (ch->name)); if (password) - strlcpy(ch->password, password, sizeof (ch->password)); + irc_util_strlcpy(ch->password, password, sizeof (ch->password)); LL_PREPEND(s->channels, ch); @@ -171,7 +171,7 @@ static void read_support_chantypes(struct irc_server *s, const char *value) { - strlcpy(s->params.chantypes, value, sizeof (s->params.chantypes)); + irc_util_strlcpy(s->params.chantypes, value, sizeof (s->params.chantypes)); } static void @@ -183,9 +183,8 @@ if (s->flags & IRC_SERVER_FLAGS_AUTO_RECO) { irc_log_info("server %s: waiting %u seconds before reconnecting", s->name, DELAY); s->state = IRC_SERVER_STATE_WAITING; - } else { + } else s->state = IRC_SERVER_STATE_DISCONNECTED; - } /* Time point when we lose signal from the server. */ s->lost_tp = time(NULL); @@ -260,11 +259,11 @@ s->name, s->params.kicklen); } else if (strcmp(key, "CHARSET") == 0) { - strlcpy(s->params.charset, value, sizeof (s->params.charset)); + irc_util_strlcpy(s->params.charset, value, sizeof (s->params.charset)); irc_log_info("server %s: charset: %s", s->name, s->params.charset); } else if (strcmp(key, "CASEMAPPING") == 0) { - strlcpy(s->params.casemapping, value, sizeof (s->params.casemapping)); + irc_util_strlcpy(s->params.casemapping, value, sizeof (s->params.casemapping)); irc_log_info("server %s: case mapping: %s", s->name, s->params.casemapping); } @@ -462,7 +461,7 @@ if (is_self(s, ev->nick.origin) == 0) { irc_log_info("server %s: nick change %s -> %s", s->name, s->ident.nickname, ev->nick.nickname); - strlcpy(s->ident.nickname, ev->nick.nickname, sizeof (s->ident.nickname)); + irc_util_strlcpy(s->ident.nickname, ev->nick.nickname, sizeof (s->ident.nickname)); } } @@ -718,19 +717,19 @@ /* Hide implementation to get rid of OpenSSL headers in public API. */ s->conn = irc_util_calloc(1, sizeof (*s->conn)); s->conn->port = port; - strlcpy(s->conn->hostname, hostname, sizeof (s->conn->hostname)); + irc_util_strlcpy(s->conn->hostname, hostname, sizeof (s->conn->hostname)); /* Identity. */ - strlcpy(s->ident.nickname, nickname, sizeof (s->ident.nickname)); - strlcpy(s->ident.username, username, sizeof (s->ident.username)); - strlcpy(s->ident.realname, realname, sizeof (s->ident.realname)); - strlcpy(s->ident.ctcpversion, "IRC Client Daemon " IRCCD_VERSION, sizeof (s->ident.ctcpversion)); + irc_util_strlcpy(s->ident.nickname, nickname, sizeof (s->ident.nickname)); + irc_util_strlcpy(s->ident.username, username, sizeof (s->ident.username)); + irc_util_strlcpy(s->ident.realname, realname, sizeof (s->ident.realname)); + irc_util_strlcpy(s->ident.ctcpversion, "IRC Client Daemon " IRCCD_VERSION, sizeof (s->ident.ctcpversion)); /* Server itself. */ - strlcpy(s->name, name, sizeof (s->name)); + irc_util_strlcpy(s->name, name, sizeof (s->name)); /* Default options. */ - strlcpy(s->prefix, "!", sizeof (s->prefix)); + irc_util_strlcpy(s->prefix, "!", sizeof (s->prefix)); return s; } @@ -1007,7 +1006,7 @@ assert(nick); if (s->state <= IRC_SERVER_STATE_DISCONNECTED) { - strlcpy(s->ident.nickname, nick, sizeof (s->ident.nickname)); + irc_util_strlcpy(s->ident.nickname, nick, sizeof (s->ident.nickname)); return 1; }
--- a/lib/irccd/subst.c Thu Jul 15 09:33:33 2021 +0200 +++ b/lib/irccd/subst.c Fri Jul 16 20:18:29 2021 +0200 @@ -115,7 +115,7 @@ { size_t written; - if ((written = strlcpy(*out, value, *outsz)) >= *outsz) + if ((written = irc_util_strlcpy(*out, value, *outsz)) >= *outsz) return errno = ENOMEM, -1; *out += written; @@ -150,7 +150,7 @@ if (p) *p = 0; - strlcpy(attrs->attrs[attrs->attrsz++], attr, sizeof (attrs->attrs[0])); + irc_util_strlcpy(attrs->attrs[attrs->attrsz++], attr, sizeof (attrs->attrs[0])); if (p) attr = p + 1;
--- a/lib/irccd/util.c Thu Jul 15 09:33:33 2021 +0200 +++ b/lib/irccd/util.c Fri Jul 16 20:18:29 2021 +0200 @@ -64,9 +64,12 @@ void * irc_util_reallocarray(void *ptr, size_t n, size_t size) { + /* extern/libbsd/reallocarray.c */ + void *openbsd_reallocarray(void *, size_t, size_t); + void *ret; - if (!(ret = reallocarray(ptr, n, size))) + if (!(ret = openbsd_reallocarray(ptr, n, size))) irc_util_die("reallocarray: %s\n", strerror(errno)); return ret; @@ -110,8 +113,8 @@ static char ret[PATH_MAX]; char tmp[PATH_MAX]; - strlcpy(tmp, str, sizeof (tmp)); - strlcpy(ret, basename(tmp), sizeof (ret)); + irc_util_strlcpy(tmp, str, sizeof (tmp)); + irc_util_strlcpy(ret, basename(tmp), sizeof (ret)); return ret; } @@ -122,8 +125,8 @@ static char ret[PATH_MAX]; char tmp[PATH_MAX]; - strlcpy(tmp, str, sizeof (tmp)); - strlcpy(ret, dirname(tmp), sizeof (ret)); + irc_util_strlcpy(tmp, str, sizeof (tmp)); + irc_util_strlcpy(ret, dirname(tmp), sizeof (ret)); return ret; }
--- a/lib/irccd/util.h Thu Jul 15 09:33:33 2021 +0200 +++ b/lib/irccd/util.h Fri Jul 16 20:18:29 2021 +0200 @@ -73,6 +73,15 @@ int irc_util_stou(const char *, unsigned long long *); +void * +irc_util_reallocarray(void *, size_t, size_t); + +size_t +irc_util_strlcpy(char *, const char *, size_t); + +size_t +irc_util_strlcat(char *, const char *, size_t); + #if defined(__cplusplus) } #endif
--- a/plugins/links/links.c Thu Jul 15 09:33:33 2021 +0200 +++ b/plugins/links/links.c Fri Jul 16 20:18:29 2021 +0200 @@ -315,7 +315,7 @@ links_set_template(const char *key, const char *value) { if (strcmp(key, "info") == 0) - strlcpy(templates[TPL_INFO], value, sizeof (templates[TPL_INFO])); + irc_util_strlcpy(templates[TPL_INFO], value, sizeof (templates[TPL_INFO])); } const char *
--- a/tests/data/example-dl-plugin.c Thu Jul 15 09:33:33 2021 +0200 +++ b/tests/data/example-dl-plugin.c Fri Jul 16 20:18:29 2021 +0200 @@ -68,7 +68,7 @@ { for (size_t i = 0; i < tablesz; ++i) { if (strcmp(table[i].key, key) == 0) { - strlcpy(table[i].value, value, sizeof (table[i].value)); + irc_util_strlcpy(table[i].value, value, sizeof (table[i].value)); break; } }