Skip to content
Permalink
Browse files

Add a fixed-buffer strcpy analogous to bprintf

  • Loading branch information...
nigoroll committed Oct 9, 2019
1 parent 8a5a9ab commit 1f226e6d8c1c5443d9df127797c62b1e1228bfd1
@@ -501,8 +501,8 @@ vca_accept_task(struct worker *wrk, void *arg)
wrk->stats->sess_fail++;

if (wa.acceptlsock->uds) {
strcpy(laddr, "0.0.0.0");
strcpy(lport, "0");
bstrcpy(laddr, "0.0.0.0");
bstrcpy(lport, "0");
} else {
VTCP_myname(ls->sock, laddr, VTCP_ADDRBUFSIZE,
lport, VTCP_PORTBUFSIZE);
@@ -104,8 +104,7 @@ WS_Init(struct ws *ws, const char *id, void *space, unsigned len)
*ws->e = 0x15;
ws->f = ws->s;
assert(id[0] & 0x20);
assert(strlen(id) < sizeof ws->id);
strcpy(ws->id, id);
bstrcpy(ws->id, id);
WS_Assert(ws);
}

@@ -278,7 +278,6 @@ smp_newsilo(struct smp_sc *sc)
struct smp_ident *si;

ASSERT_MGT();
assert(strlen(SMP_IDENT_STRING) < sizeof si->ident);

/* Choose a new random number */
AZ(VRND_RandomCrypto(&sc->unique, sizeof sc->unique));
@@ -287,7 +286,7 @@ smp_newsilo(struct smp_sc *sc)
si = sc->ident;

memset(si, 0, sizeof *si);
strcpy(si->ident, SMP_IDENT_STRING);
bstrcpy(si->ident, SMP_IDENT_STRING);
si->byte_order = 0x12345678;
si->size = sizeof *si;
si->major_version = 2;
@@ -406,7 +406,7 @@ smu_open(struct stevedore *st)

smu_open_init();

AN(strcpy(ident, st->ident));
bstrcpy(ident, st->ident);
smu_sc->smu_cache = umem_cache_createf(ident,
sizeof(struct smu),
0, // align
@@ -343,7 +343,7 @@ server_dispatch_thread(void *priv)
vtc_log(vl, 3, "dispatch fd %d -> %s", fd, snbuf);
s2 = server_new(snbuf, vl);
s2->spec = s->spec;
strcpy(s2->listen, s->listen);
bstrcpy(s2->listen, s->listen);
s2->fd = fd;
s2->run = 1;
AZ(pthread_create(&s2->tp, NULL, server_dispatch_wrk, s2));
@@ -508,7 +508,7 @@ varnish_launch(struct varnish *v)
assert(nfd >= 0);

assert(sizeof abuf >= CLI_AUTH_RESPONSE_LEN + 7);
strcpy(abuf, "auth ");
bstrcpy(abuf, "auth ");
VCLI_AuthResponse(nfd, r, abuf + 5);
closefd(&nfd);
free(r);
@@ -56,6 +56,16 @@
assert(ivbprintf >= 0 && ivbprintf < (int)sizeof buf); \
} while (0)

/* Safe strcpy into a fixed-size buffer */
#define bstrcpy(dst, src) \
do { \
size_t lbstrcpy = strlen(src) + 1; \
assert(lbstrcpy <= sizeof dst); \
memcpy(dst, src, lbstrcpy); \
} while (0)

// TODO #define strcpy BANNED

/* Close and discard filedescriptor */
#define closefd(fdp) \
do { \

0 comments on commit 1f226e6

Please sign in to comment.
You can’t perform that action at this time.