diff options
author | Omar Polo <op@omarpolo.com> | 2024-06-06 13:43:12 +0000 |
---|---|---|
committer | Omar Polo <op@omarpolo.com> | 2024-06-06 13:43:12 +0000 |
commit | 848189f10a98768b372186de8b9fe013ad49d4e5 (patch) | |
tree | e2d451bf4bbc6ac51e0ea98f1ad9cd409f408aa8 | |
parent | 1bc73c3bcbd85e2682afca36595ea44a75345e65 (diff) |
attempt to deal with the portability fiasco of strnvis(3)
-rwxr-xr-x | configure | 9 | ||||
-rw-r--r-- | ge.c | 2 | ||||
-rw-r--r-- | gmid.c | 2 | ||||
-rw-r--r-- | gmid.h | 1 | ||||
-rw-r--r-- | have/broken-strnvis.c | 15 | ||||
-rw-r--r-- | utils.c | 17 |
6 files changed, 44 insertions, 2 deletions
@@ -275,6 +275,7 @@ fi HAVE_ENDIAN_H=0 HAVE_SYS_ENDIAN_H=0 HAVE_MACHINE_ENDIAN=0 +HAVE_BROKEN_STRNVIS=0 runtest endian_h ENDIAN_H || \ runtest sys_endian_h SYS_ENDIAN_H || \ @@ -317,6 +318,12 @@ runtest tree_h TREE_H || true runtest vasprintf VASPRINTF -D_GNU_SOURCE || true runtest vis VIS -DLIBBSD_OPENBSD_VIS || true +if [ ${HAVE_VIS} -eq 1 ]; then + if singletest broken-strnvis BROKEN_STRNVIS "-Wall -Werror"; then + HAVE_BROKEN_STRNVIS=1 + fi +fi + if [ ${HAVE_ARC4RANDOM} -eq 1 -a ${HAVE_ARC4RANDOM_BUF} -eq 0 ]; then COMPATS="compat/arc4random.c ${COMPATS}" fi @@ -648,6 +655,8 @@ cat <<__HEREDOC__ # define HOST_NAME_MAX 255 # endif #endif + +#define HAVE_BROKEN_STRNVIS ${HAVE_BROKEN_STRNVIS} __HEREDOC__ echo "file config.h: written" 1>&2 @@ -83,7 +83,7 @@ log_request(struct client *c, int code, const char *meta) strlcpy(cntmp, subj + 4, sizeof(cntmp)); if ((n = strchr(cntmp, '/')) != NULL) *n = '\0'; - strnvis(cn, cntmp, sizeof(cn), VIS_WHITE|VIS_DQ); + gmid_strnvis(cn, cntmp, sizeof(cn), VIS_WHITE|VIS_DQ); } } @@ -140,7 +140,7 @@ log_request(struct client *c, int code, const char *meta) strlcpy(cntmp, subj + 4, sizeof(cntmp)); if ((n = strchr(cntmp, '/')) != NULL) *n = '\0'; - strnvis(cn, cntmp, sizeof(cn), VIS_WHITE|VIS_DQ); + gmid_strnvis(cn, cntmp, sizeof(cn), VIS_WHITE|VIS_DQ); } } @@ -469,5 +469,6 @@ EVP_PKEY *ssl_load_pkey(const uint8_t *, size_t); struct vhost *new_vhost(void); struct location *new_location(void); struct proxy *new_proxy(void); +int gmid_strnvis(char *, const char *, size_t, int); #endif diff --git a/have/broken-strnvis.c b/have/broken-strnvis.c new file mode 100644 index 0000000..f2a9a59 --- /dev/null +++ b/have/broken-strnvis.c @@ -0,0 +1,15 @@ +/* + * public domain + */ + +#include <stdio.h> +#include <stdlib.h> +#include <vis.h> + +int +main(void) +{ + char buf[128]; + + return strnvis(buf, sizeof(buf), "Hello, world!\n", 0); +} @@ -22,6 +22,7 @@ #include <errno.h> #include <string.h> +#include <vis.h> /* for gmid_strnvis() */ #include <openssl/ec.h> #include <openssl/err.h> @@ -496,3 +497,19 @@ new_proxy(void) p->protocols = TLS_PROTOCOLS_DEFAULT; return p; } + +/* + * I can't rant enough about this situation. As far as I've understood, + * OpenBSD introduced strnvis(3) with a signature, then NetBSD did it but + * with a incompatible signature. FreeBSD followed NetBSD. libbsd followed + * OpenBSD but now is thinking to switch. WTF? + */ +int +gmid_strnvis(char *dst, const char *src, size_t destsize, int flag) +{ +#if HAVE_BROKEN_STRNVIS + return strnvis(dst, destsize, src, flag); +#else + return strnvis(dst, src, destsize, flag); +#endif +} |