Skip to content

Commit

Permalink
change the approach for strnvis
Browse files Browse the repository at this point in the history
instead of making things more obscure via gmid_strnvis(), let's
just check for strnvis with -Werror so we can swap the OS broken
implementation with the bundled OpenBSD one.
  • Loading branch information
omar-polo committed Jun 8, 2024
1 parent fcf3f1f commit 4010301
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 48 deletions.
17 changes: 5 additions & 12 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ 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 || \
Expand Down Expand Up @@ -316,12 +315,12 @@ runtest strtonum STRTONUM -D_OPENBSD_SOURCE || true
runtest timingsafe_memcmp TIMINGSAFE_MEMCMP || true
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
# strnvis is a bit special since NetBSD, FreeBSD and MacOS have
# the broken version with the wrong semantics and arguments.
# Hence the -Wall -Werror check.
if ! singletest strnvis STRNVIS "-Wall -Werror"; then
CFLAGS="-I ${PWD}/compat/vis ${CFLAGS} ${CFLAGS}"
fi

if [ ${HAVE_ARC4RANDOM} -eq 1 -a ${HAVE_ARC4RANDOM_BUF} -eq 0 ]; then
Expand Down Expand Up @@ -395,10 +394,6 @@ if [ ${HAVE_QUEUE_H} -eq 0 -o ${HAVE_IMSG} -eq 0 -o ${HAVE_TREE_H} -eq 0 ]; then
CFLAGS="${CFLAGS} -I ${PWD}/compat"
fi

if [ ${HAVE_VIS} -eq 0 ]; then
CFLAGS="${CFLAGS} -I ${PWD}/compat/vis"
fi

if [ $HAVE_LIBEVENT2 -eq 1 ]; then
CFLAGS="$CFLAGS -DHAVE_LIBEVENT2=1"
fi
Expand Down Expand Up @@ -655,8 +650,6 @@ cat <<__HEREDOC__
# define HOST_NAME_MAX 255
# endif
#endif
#define HAVE_BROKEN_STRNVIS ${HAVE_BROKEN_STRNVIS}
__HEREDOC__

echo "file config.h: written" 1>&2
Expand Down
2 changes: 1 addition & 1 deletion ge.c
Original file line number Diff line number Diff line change
Expand Up @@ -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';
gmid_strnvis(cn, cntmp, sizeof(cn), VIS_WHITE|VIS_DQ);
strnvis(cn, cntmp, sizeof(cn), VIS_WHITE|VIS_DQ);
}
}

Expand Down
2 changes: 1 addition & 1 deletion gmid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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';
gmid_strnvis(cn, cntmp, sizeof(cn), VIS_WHITE|VIS_DQ);
strnvis(cn, cntmp, sizeof(cn), VIS_WHITE|VIS_DQ);
}
}

Expand Down
1 change: 0 additions & 1 deletion gmid.h
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,5 @@ 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
3 changes: 1 addition & 2 deletions have/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ DISTFILES = ASN1_time_parse.c \
X509_LOOKUP_mem.c \
arc4random.c \
arc4random_buf.c \
broken-strnvis.c \
endian_h.c \
err.c \
explicit_bzero.c \
Expand Down Expand Up @@ -35,12 +34,12 @@ DISTFILES = ASN1_time_parse.c \
setresuid.c \
strlcat.c \
strlcpy.c \
strnvis.c \
strtonum.c \
sys_endian_h.c \
timingsafe_memcmp.c \
tree_h.c \
vasprintf.c \
vis.c \
wait_any.c

all:
Expand Down
15 changes: 0 additions & 15 deletions have/broken-strnvis.c

This file was deleted.

File renamed without changes.
16 changes: 0 additions & 16 deletions utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -497,19 +497,3 @@ 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
}

0 comments on commit 4010301

Please sign in to comment.