* [PATCH v3] repair, passt-repair: Build and warning fixes for musl
@ 2025-02-15 11:56 Stefano Brivio
2025-02-17 3:58 ` David Gibson
0 siblings, 1 reply; 2+ messages in thread
From: Stefano Brivio @ 2025-02-15 11:56 UTC (permalink / raw)
To: passt-dev; +Cc: David Gibson
Checked against musl 1.2.5.
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
---
v3: Now 100% more trusted, with cppcheck absolutely positive about us
initialising 'buf'.
v2: Now 100% more tested: don't try to use the whole buffer as
msg_controllen.
passt-repair.c | 4 +++-
repair.c | 13 +++++++++----
2 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/passt-repair.c b/passt-repair.c
index 1174ae3..e0c366e 100644
--- a/passt-repair.c
+++ b/passt-repair.c
@@ -63,6 +63,7 @@ int main(int argc, char **argv)
struct cmsghdr *cmsg;
struct msghdr msg;
struct iovec iov;
+ size_t cmsg_len;
int op;
prctl(PR_SET_DUMPABLE, 0);
@@ -138,8 +139,9 @@ loop:
}
}
if (!n) {
+ cmsg_len = cmsg->cmsg_len; /* socklen_t is 'unsigned' on musl */
fprintf(stderr, "Invalid ancillary data length %zu from peer\n",
- cmsg->cmsg_len);
+ cmsg_len);
_exit(1);
}
diff --git a/repair.c b/repair.c
index d288617..dac28a6 100644
--- a/repair.c
+++ b/repair.c
@@ -13,6 +13,7 @@
*/
#include <errno.h>
+#include <sys/socket.h>
#include <sys/uio.h>
#include "util.h"
@@ -145,9 +146,9 @@ void repair_handler(struct ctx *c, uint32_t events)
*/
int repair_flush(struct ctx *c)
{
- struct iovec iov = { &repair_cmd, sizeof(repair_cmd) };
char buf[CMSG_SPACE(sizeof(int) * SCM_MAX_FD)]
- __attribute__ ((aligned(__alignof__(struct cmsghdr))));
+ __attribute__ ((aligned(__alignof__(struct cmsghdr)))) = { 0 };
+ struct iovec iov = { &repair_cmd, sizeof(repair_cmd) };
struct cmsghdr *cmsg;
struct msghdr msg;
int8_t reply;
@@ -155,8 +156,12 @@ int repair_flush(struct ctx *c)
if (!repair_nfds)
return 0;
- msg = (struct msghdr){ NULL, 0, &iov, 1,
- buf, CMSG_SPACE(sizeof(int) * repair_nfds), 0 };
+ msg = (struct msghdr){ .msg_name = NULL, .msg_namelen = 0,
+ .msg_iov = &iov, .msg_iovlen = 1,
+ .msg_control = buf,
+ .msg_controllen = CMSG_SPACE(sizeof(int) *
+ repair_nfds),
+ .msg_flags = 0 };
cmsg = CMSG_FIRSTHDR(&msg);
cmsg->cmsg_level = SOL_SOCKET;
--
@@ -13,6 +13,7 @@
*/
#include <errno.h>
+#include <sys/socket.h>
#include <sys/uio.h>
#include "util.h"
@@ -145,9 +146,9 @@ void repair_handler(struct ctx *c, uint32_t events)
*/
int repair_flush(struct ctx *c)
{
- struct iovec iov = { &repair_cmd, sizeof(repair_cmd) };
char buf[CMSG_SPACE(sizeof(int) * SCM_MAX_FD)]
- __attribute__ ((aligned(__alignof__(struct cmsghdr))));
+ __attribute__ ((aligned(__alignof__(struct cmsghdr)))) = { 0 };
+ struct iovec iov = { &repair_cmd, sizeof(repair_cmd) };
struct cmsghdr *cmsg;
struct msghdr msg;
int8_t reply;
@@ -155,8 +156,12 @@ int repair_flush(struct ctx *c)
if (!repair_nfds)
return 0;
- msg = (struct msghdr){ NULL, 0, &iov, 1,
- buf, CMSG_SPACE(sizeof(int) * repair_nfds), 0 };
+ msg = (struct msghdr){ .msg_name = NULL, .msg_namelen = 0,
+ .msg_iov = &iov, .msg_iovlen = 1,
+ .msg_control = buf,
+ .msg_controllen = CMSG_SPACE(sizeof(int) *
+ repair_nfds),
+ .msg_flags = 0 };
cmsg = CMSG_FIRSTHDR(&msg);
cmsg->cmsg_level = SOL_SOCKET;
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v3] repair, passt-repair: Build and warning fixes for musl
2025-02-15 11:56 [PATCH v3] repair, passt-repair: Build and warning fixes for musl Stefano Brivio
@ 2025-02-17 3:58 ` David Gibson
0 siblings, 0 replies; 2+ messages in thread
From: David Gibson @ 2025-02-17 3:58 UTC (permalink / raw)
To: Stefano Brivio; +Cc: passt-dev
[-- Attachment #1: Type: text/plain, Size: 2639 bytes --]
On Sat, Feb 15, 2025 at 12:56:08PM +0100, Stefano Brivio wrote:
> Checked against musl 1.2.5.
>
> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> ---
> v3: Now 100% more trusted, with cppcheck absolutely positive about us
> initialising 'buf'.
>
> v2: Now 100% more tested: don't try to use the whole buffer as
> msg_controllen.
>
> passt-repair.c | 4 +++-
> repair.c | 13 +++++++++----
> 2 files changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/passt-repair.c b/passt-repair.c
> index 1174ae3..e0c366e 100644
> --- a/passt-repair.c
> +++ b/passt-repair.c
> @@ -63,6 +63,7 @@ int main(int argc, char **argv)
> struct cmsghdr *cmsg;
> struct msghdr msg;
> struct iovec iov;
> + size_t cmsg_len;
> int op;
>
> prctl(PR_SET_DUMPABLE, 0);
> @@ -138,8 +139,9 @@ loop:
> }
> }
> if (!n) {
> + cmsg_len = cmsg->cmsg_len; /* socklen_t is 'unsigned' on musl */
> fprintf(stderr, "Invalid ancillary data length %zu from peer\n",
> - cmsg->cmsg_len);
> + cmsg_len);
> _exit(1);
> }
>
> diff --git a/repair.c b/repair.c
> index d288617..dac28a6 100644
> --- a/repair.c
> +++ b/repair.c
> @@ -13,6 +13,7 @@
> */
>
> #include <errno.h>
> +#include <sys/socket.h>
> #include <sys/uio.h>
>
> #include "util.h"
> @@ -145,9 +146,9 @@ void repair_handler(struct ctx *c, uint32_t events)
> */
> int repair_flush(struct ctx *c)
> {
> - struct iovec iov = { &repair_cmd, sizeof(repair_cmd) };
> char buf[CMSG_SPACE(sizeof(int) * SCM_MAX_FD)]
> - __attribute__ ((aligned(__alignof__(struct cmsghdr))));
> + __attribute__ ((aligned(__alignof__(struct cmsghdr)))) = { 0 };
> + struct iovec iov = { &repair_cmd, sizeof(repair_cmd) };
> struct cmsghdr *cmsg;
> struct msghdr msg;
> int8_t reply;
> @@ -155,8 +156,12 @@ int repair_flush(struct ctx *c)
> if (!repair_nfds)
> return 0;
>
> - msg = (struct msghdr){ NULL, 0, &iov, 1,
> - buf, CMSG_SPACE(sizeof(int) * repair_nfds), 0 };
> + msg = (struct msghdr){ .msg_name = NULL, .msg_namelen = 0,
> + .msg_iov = &iov, .msg_iovlen = 1,
> + .msg_control = buf,
> + .msg_controllen = CMSG_SPACE(sizeof(int) *
> + repair_nfds),
> + .msg_flags = 0 };
> cmsg = CMSG_FIRSTHDR(&msg);
>
> cmsg->cmsg_level = SOL_SOCKET;
--
David Gibson (he or they) | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you, not the other way
| around.
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-02-17 3:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-15 11:56 [PATCH v3] repair, passt-repair: Build and warning fixes for musl Stefano Brivio
2025-02-17 3:58 ` David Gibson
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).