misty
misty copied to clipboard
Problems when building misty for ARMv7 and musl libc.
I've compiled misty in a docker container based on python:3.10-alpine for armv7.
There I use musl libc and gcc-13.2.1.
I first had to do this fix to get mstplib to compile:
diff --git a/misty/bacnet-stack-0.8.4/ports/linux/dlmstp_linux.h b/misty/bacnet-stack-0.8.4/ports/linux/dlmstp_linux.h
index 9cd09ce..49da38c 100644
--- a/misty/bacnet-stack-0.8.4/ports/linux/dlmstp_linux.h
+++ b/misty/bacnet-stack-0.8.4/ports/linux/dlmstp_linux.h
@@ -27,7 +27,8 @@
#include "mstp.h"
/*#include "dlmstp.h" */
#ifdef __linux__
-#include "bits/pthreadtypes.h"
+// #include "bits/pthreadtypes.h"
+#include "sys/types.h"
#endif
#include <semaphore.h>
Then I got this warning:
mstp_agent.c: In function 'set_interface_params':
mstp_agent.c:222:9: warning: 'sprintf' argument 3 overlaps destination object 'port_info_array' [-Wrestrict]
222 | sprintf(port_info_ptr->mstp_client_path, "%s%s",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
223 | port_info_ptr->server_info.LEADING_PART, path);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mstp_agent.c:31:13: note: destination object referenced by 'restrict'-qualified argument 1 was declared here
31 | port_info_t port_info_array[MAX_PORTS];
I've not bothered to look into it yet.
Other than that it compiles fine. When I try to run misty/misty/samples/CommandableMixin.py
I get a FileNotFound error when the python code tries to open the unix domain socket. I first increased the sleep before from 0.5 to 5.0 seconds to give the server more time to start, but that didn't help.
I then noticed that the path to the server domain socket in mstplib is copied from the tmp
array with realpath
. The problem is that it is undefined what realpath
does with the destination when the path isn't valid (like here). With musl libc it returns NULL and sets errno to ENOENT but doesn't touch the destination. With libc6 it also returns NULL and sets errno to ENOENT, but it also copies the path to the destination. Since the path isn't validated anyway before the socket tries to create it, I changed the two calls to realpath
into a call to strcpy
and then it seems to work:
diff --git a/misty/mstplib/mstp_agent.c b/misty/mstplib/mstp_agent.c
index b43427e..e259b6b 100644
--- a/misty/mstplib/mstp_agent.c
+++ b/misty/mstplib/mstp_agent.c
@@ -317,12 +317,15 @@ void start_server(char *dir_path, int port_index)
memset(tmp, 0, sizeof(tmp));
sprintf(tmp, "%s/mstp", dir_path);
- realpath(tmp, port_info_ptr->server_info.LEADING_PART);
+
+ // realpath(tmp, port_info_ptr->server_info.LEADING_PART);
+ strcpy(port_info_ptr->server_info.LEADING_PART, tmp);
memset(tmp, 0, sizeof(tmp));
memset(server_path, 0, sizeof(server_path));
sprintf(tmp, "%s/mstp_server", dir_path);
- realpath(tmp, server_path);
+ // realpath(tmp, server_path);
+ strcpy(server_path, tmp);
debug_printf("server_path = %s LEADING_PART=%s \n", server_path,
port_info_ptr->server_info.LEADING_PART);
A proper implementation should of course use strlcpy or strncpy instead.