Closed g2gps closed 1 year ago
FD_ZERO
should be defined as explicit_bzero
and having select.h
including string
#include <nuttx/config.h>
#include <limits.h>
#include <stdint.h>
#include <signal.h>
+#include <string.h>
#include <sys/time.h> // -> is including #include <sys/select.h> bad juju
#ifdef CONFIG_FDCHECK
# include <nuttx/fdcheck.h>
#endif
...
or something like
#ifndef CONFIG_SOME_DONT_WANT_STRING_AVAILABILITY_HERE
static inline void explicit_bzero(FAR void * s, size_t n)
{ unsigned char * p = s; while (n-- > 0) { *p++ = 0; } }
#else
EXTERN void explicit_bzero(FAR void * s, size_t n);
#endif
because select.h
references that symbol: it is then the owner unit
, change should be made in that header.
#define FD_ZERO(set) \
explicit_bzero((set), sizeof(fd_set))
@g2gps make import
because there is certainly a conditional include somewhere prior or that:
CFLAGS += -Wno-implicit-function-declaration
FD_ZERO is often used
with its companion FD_SET and such within select
loops in multi-threaded environments, if there is a compiler optimization regarding memset
it can cause all sort of overflow
conditions ; from a security point of view: you really want FD_ZERO to guarantee that zeroing happens ; so explicit_bzero
should be used in place.
@g2gps the simplest method is:
I'm building a third party library against Nuttx export, with CONFIG_BUILD_KERNEL.
When building:
I receive the warning:
But interestingly, when I modify an existing Nuttx example, in this case "hello", like this:
I don't receive any warning.
I'm building hello_main.c with:
The resulting Make.dep for hello_main is:
I may be missing something obvious, but I can't see where the definition for
memset
is coming from?Naturally, the issue could be fixed by adding
#include <string.h>
tosys/select.h
, but it would be nice to understand why the same warning doesn't occur when building using Nuttx'smake import
from the apps directory.