From: Andrew Bartlett Date: Thu, 9 Feb 2017 01:03:33 +0000 (+1300) Subject: messaging_dgm: avoid GCC snprintf warnings in messaging_dgm_out_create X-Git-Tag: talloc-2.1.9~212 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=34b0ee832850e5a01b337caf70677bdae6eea551;p=thirdparty%2Fsamba.git messaging_dgm: avoid GCC snprintf warnings in messaging_dgm_out_create We are trying to put something that (in theory) could be 109 bytes long, into the sockaddr_un.sun_path field which has a fixed size of 108 bytes. The "in theory" part is that one of the components is a pid, which although stored as 32 bits is in practice 16 bits, so the maximum size is not actually hit. This is all very annoying, because the length is checked anyway and all this achieves is silencing a warning. Reviewed-by: Douglas Bagnall Reviewed-by: Andrew Bartlett Autobuild-User(master): Andrew Bartlett Autobuild-Date(master): Fri Feb 10 09:05:31 CET 2017 on sn-devel-144 --- diff --git a/source3/lib/messages_dgm.c b/source3/lib/messages_dgm.c index 49b390317e4..dff8357f60d 100644 --- a/source3/lib/messages_dgm.c +++ b/source3/lib/messages_dgm.c @@ -212,6 +212,7 @@ static int messaging_dgm_out_create(TALLOC_CTX *mem_ctx, struct sockaddr_un addr = { .sun_family = AF_UNIX }; int ret = ENOMEM; int out_pathlen; + char addr_buf[sizeof(addr.sun_path) + (3 * sizeof(unsigned) + 2)]; out = talloc(mem_ctx, struct messaging_dgm_out); if (out == NULL) { @@ -224,7 +225,7 @@ static int messaging_dgm_out_create(TALLOC_CTX *mem_ctx, .cookie = 1 }; - out_pathlen = snprintf(addr.sun_path, sizeof(addr.sun_path), + out_pathlen = snprintf(addr_buf, sizeof(addr_buf), "%s/%u", ctx->socket_dir.buf, (unsigned)pid); if (out_pathlen < 0) { goto errno_fail; @@ -234,6 +235,8 @@ static int messaging_dgm_out_create(TALLOC_CTX *mem_ctx, goto fail; } + memcpy(addr.sun_path, addr_buf, out_pathlen + 1); + out->queue = tevent_queue_create(out, addr.sun_path); if (out->queue == NULL) { ret = ENOMEM;