Commit Graph

1456 Commits

Author SHA1 Message Date
guoshichao af53d7a178 libs/libc/aio/lio_listio: fix the heap use-after-free bug
1. the lio_sigsetup() method use a universal sighand instance across all
aiocb instances, but inside the lio_sighandler() method, if one aiocb is
handle finished, then this method will free the sighand instance that
come along with current aiocb instance. thus when handle next aiocb
instance, use-after-free crash will happen. in order to solve this
problem, we make each aiocb instance have their own sighand instance
2. make the lio_listio implementation can pass the
ltp/open_posix_testsuite/lio_listio testcases
3. the modification are referred to https://pubs.opengroup.org/onlinepubs/9699919799/functions/lio_listio.html

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-07-03 13:37:34 +08:00
guoshichao 4af8c58b93 libs/libc/locale/langinfo: implement the nl_langinfo function
1. the nl_langinfo can help to pass the
ltp/open_posix_testsuite/strftime testcases
2. the implementation are referred to https://pubs.opengroup.org/onlinepubs/9699919799/functions/nl_langinfo.html

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-07-02 13:57:36 +08:00
Junbo Zheng 0d3252ba06 libs/libc: fix locale/lib_iconv.c:538:23: warning: dereference of NULL ‘scd’ [CWE-690] [-Wanalyzer-null-dereference] by -fanalyzer
CC:  signal/sig_queue.c locale/lib_iconv.c: In function ‘iconv’:
locale/lib_iconv.c:538:23: warning: dereference of NULL ‘scd’ [CWE-690] [-Wanalyzer-null-dereference]
  538 |               if (!scd->state)
      |                    ~~~^~~~~~~
  ‘iconv’: events 1-5
    |
    |  413 |   x = 0;
    |      |   ~~^~~
    |      |     |
    |      |     (1) ‘scd’ is NULL
    |  414 |   scd = NULL;
    |  415 |   if (((size_t)cd & 1) == 0)
    |      |      ~
    |      |      |
    |      |      (2) following ‘false’ branch...
    |......
    |  421 |   to = extract_to(cd);
    |      |        ~~~~~~~~~~~~~~
    |      |        |
    |      |        (3) ...to here
    |......
    |  428 |   if (in == NULL || *in == NULL || *inb == 0)
    |      |      ~              ~~~
    |      |      |              |
    |      |      |              (5) ...to here
    |      |      (4) following ‘false’ branch (when ‘in’ is non-NULL)...
    |
  ‘iconv’: events 6-8
    |
    |  428 |   if (in == NULL || *in == NULL || *inb == 0)
    |      |       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
    |      |                  |              |  |
    |      |                  |              |  (7) ...to here
    |      |                  |              (8) following ‘false’ branch...
    |      |                  (6) following ‘false’ branch...
    |
  ‘iconv’: event 9
    |
    |cc1:
    | (9): ...to here
    |
  ‘iconv’: events 10-14
    |
    |  433 |   for (; *inb; *in += l, *inb -= l)
    |      |   ^~~
    |      |   |
    |      |   (10) following ‘true’ branch...
    |  434 |     {
    |  435 |       c = *(FAR unsigned char *)*in;
    |      |            ~~~~~~~~~~~~~~~~~~~~~~~~
    |      |            |
    |      |            (11) ...to here
    |......
    |  438 |       switch (type)
    |      |       ~~~~~~
    |      |       |
    |      |       (12) following ‘case 200:’ branch...
    |......
    |  529 |           case UCS2:
    |      |           ~~~~
    |      |           |
    |      |           (13) ...to here
    |......
    |  538 |               if (!scd->state)
    |      |                    ~~~~~~~~~~
    |      |                       |
    |      |                       (14) dereference of NULL ‘scd’
    |
locale/lib_iconv.c:565:23: warning: dereference of NULL ‘scd’ [CWE-690] [-Wanalyzer-null-dereference]
  565 |               if (!scd->state)
      |                    ~~~^~~~~~~
  ‘iconv’: events 1-5
    |
    |  413 |   x = 0;
    |      |   ~~^~~
    |      |     |
    |      |     (1) ‘scd’ is NULL
    |  414 |   scd = NULL;
    |  415 |   if (((size_t)cd & 1) == 0)
    |      |      ~
    |      |      |
    |      |      (2) following ‘false’ branch...
    |......
    |  421 |   to = extract_to(cd);
    |      |        ~~~~~~~~~~~~~~
    |      |        |
    |      |        (3) ...to here
    |......
    |  428 |   if (in == NULL || *in == NULL || *inb == 0)
    |      |      ~              ~~~
    |      |      |              |
    |      |      |              (5) ...to here
    |      |      (4) following ‘false’ branch (when ‘in’ is non-NULL)...
    |
  ‘iconv’: events 6-8
    |
    |  428 |   if (in == NULL || *in == NULL || *inb == 0)
    |      |       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
    |      |                  |              |  |
    |      |                  |              |  (7) ...to here
    |      |                  |              (8) following ‘false’ branch...
    |      |                  (6) following ‘false’ branch...
    |
  ‘iconv’: event 9
    |
    |cc1:
    | (9): ...to here
    |
  ‘iconv’: events 10-14
    |
    |  433 |   for (; *inb; *in += l, *inb -= l)
    |      |   ^~~
    |      |   |
    |      |   (10) following ‘true’ branch...
    |  434 |     {
    |  435 |       c = *(FAR unsigned char *)*in;
    |      |            ~~~~~~~~~~~~~~~~~~~~~~~~
    |      |            |
    |      |            (11) ...to here
    |......
    |  438 |       switch (type)
    |      |       ~~~~~~
    |      |       |
    |      |       (12) following ‘case 202:’ branch...
    |......
    |  557 |           case UTF_32:
    |      |           ~~~~
    |      |           |
    |      |           (13) ...to here
    |......
    |  565 |               if (!scd->state)
    |      |                    ~~~~~~~~~~
    |      |                       |
    |      |                       (14) dereference of NULL ‘scd’
    |

Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
2023-06-30 16:11:10 +08:00
guoshichao 083c11ef1a libs/libc/time/strftime: complete the strftime implementation
1. make the strftime implementation can pass the
ltp/open_posix_testsuite/strftime/1-1 testcase
2. the modification are referred to https://pubs.opengroup.org/onlinepubs/9699919799/functions/strftime.html

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-06-30 12:02:23 +08:00
guoshichao d5f45dc33b libs/libc/aio: fix aio_cancel compatible issue
1. make the aio_cancel implementation can pass the
ltp/open_posix_testsuite/aio_cancel testcases
2. the modification are referred to https://pubs.opengroup.org/onlinepubs/9699919799/functions/aio_cancel.html

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-06-29 23:25:33 +08:00
Mingjie Shen f5a2741ec2 libc/lib_remove: fix TOCTOU race condition
Separately checking the state of a file before operating on it may allow
an attacker to modify the file between the two operations.

Reference:
  CWE-367
  4290aed051/sysdeps/posix/remove.c (L29-L41)

Signed-off-by: Mingjie Shen <shen497@purdue.edu>
2023-06-29 18:15:06 +08:00
Huang Qi f48a92810b libc.csv: Correct return type of strchr
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2023-06-28 18:23:52 +08:00
guoshichao 0d9e7be323 libs/libc/aio: fix aio_return compatible bug
1. make the aio_return implementation can pass the
ltp/open_posix_testsuite/aio_return testcases
2. the modification are referred to https://pubs.opengroup.org/onlinepubs/9699919799/functions/aio_return.html

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-06-28 15:17:35 +08:00
Xiang Xiao b64c029080 libc/pwd: Correct the geos related comment and ddd ROOT_GEOS macro
fix the minor issue in https://github.com/apache/nuttx/pull/7998

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-27 16:18:57 -03:00
Xiang Xiao f1f33917f7 libc/pwd: Reuse g_passwd and g_passwd_buffer in getpwbuf
like other similar functions(e.g. getpwnam and getpwuid)

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-27 16:18:57 -03:00
guoshichao 6c60c7df07 libs/libc/aio: fix aio_error compatible bug
1. make the aio_error implementation can pass the
ltp/open_posix_testsuite/aio_error testcases
2. the modification are referred to https://pubs.opengroup.org/onlinepubs/9699919799/functions/aio_error.html

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-06-27 10:10:37 -03:00
guoshichao 037a6f5836 libs/libc/signal: add killpg function
1. the killpg function can make all the
ltp/open_posix_testsuite/killpg testcaes passed
2. Nuttx do not support process group, so we use kill process instead
3. the implementation are referred to:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/killpg.html

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-06-27 13:26:20 +08:00
Xiang Xiao 7f80b4aeba clock: Move the content of include/nuttx/time.h to include/nuttx/clock.h
and remove include/nuttx/time.h to reduce the nuttx specific header files

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-26 19:14:08 +03:00
Xiang Xiao b5c48f3ed8 binfmt: Always include arch/elf.h in include/nuttx/elf.h
since symbols defined in arch/elf.h is also used in other case, for example:
CC:  pthread/pthread_testcancel.c machine/arm/gnu_unwind_find_exidx.c:32:8: error: unknown type name '__EIT_entry'
   32 | static __EIT_entry *__exidx_start_elf;
      |        ^~~~~~~~~~~

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-25 19:02:53 -03:00
guoshichao 3821ad514d libs/libc/unistd: add getpgrp function
1. the getpgrp function can help to pass the ltp/open_posix_teststuite/killpg related testcases
2. Nuttx do not support process group, so we use getpid to implement this
3. the implementation are referred to: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpgrp.html

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-06-26 01:03:36 +08:00
anjiahao 1711a298a8 libc/semaphore:Set the flag need AND SEM_PRIO_MASK
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-06-22 16:08:03 +08:00
Alan Carvalho de Assis 9b8eedd218 lib_strftime: Also fix %l to avoid printing 0:xx AM/PM 2023-06-21 12:18:00 +08:00
Alan Carvalho de Assis 95f131c3c2 lib_strftime: Fix %I to avoid printing 00:xx AM/PM
Currently strftime is printing 00:00 AM and 00:00 PM instead of
12:00 AM and 12:00 PM when using %I.

This commit fixes this issue!
2023-06-21 12:18:00 +08:00
Xiang Xiao 1a06f7a2c9 libc: memfd_create should create /tmp/memfd/ before creating file
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-20 20:14:20 +03:00
Xiang Xiao 43f9abf84f libc: Prefer to implement memfd on top of shm
since shm can work in protected and kernel mode too

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-20 20:14:20 +03:00
simbit18 f930b4f6f5 Fix Kconfig style
Remove TABs from Kconfig files
Replace help => ---help---
Add comments
2023-06-20 12:54:50 -03:00
Bowen Wang 8515294caa lib_syslograwstream: fix bug when iob alloc failed
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2023-06-17 19:33:41 +08:00
zhangyuan21 514e77b75e semaphore: Optimize priority inheritance with only one holder
This PR is a modification that optimizes priority inheritance
for only one holder. After the above modifications are completed,
the mutex lock->unlock process that supports priority inheritance
can be optimized by 200 cycles.

Before modify: 2000 cycle
After modify: 1742 cycle

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-06-17 08:26:46 +03:00
Xiang Xiao 14e5bcaf6e fs/fdcheck: Let FDCHECK depend on SCHED_HAVE_PARENT
since the implementation of fdcheck call getppid

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-16 18:08:05 +03:00
Xiang Xiao c49bf046bd libc/fdcheck: Fix undefined reference to `getppid'
and change get[p]pid to  _SCHED_GET[P]PID

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-16 08:31:16 +03:00
zhanghongyu b723e90356 fs: move memset to upper lever for statfs
if struct statfs add new members, such as f_fsid, no additional code
changes are required.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-06-16 11:10:25 +08:00
hujun5 b2ff151282 libc/fdcheck: if pid_expect is 0, fdcheck does not take effect
there are some user code like this:
  /* close all inherited fds */
  for (i = 3; i < maxfds; i++)
    func (i);

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2023-06-15 03:29:17 +08:00
hujun5 04db52612e libc/fdcheck: child process that uses the parent process'fd will crash
In many cases, it is legal for the child process to use the fd
created by the parent process,
so to improve compatibility, we allow the child process
to use the fd of the Parent process.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2023-06-15 03:29:17 +08:00
wangchen 693898d566 netdb/dns: fix dns wrong response ID error
In every dns query, we use the new socket to avoid receiving last response ID

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2023-06-15 03:20:46 +08:00
yanghuatao 29a336d6a8 sched/tls: remove PTHREAD_CLEANUP from Kconfig
use PTHREAD_CLEANUP_STACKSIZE to enable or disable interfaces pthread_cleanup_push() and pthread_cleanup_pop().
reasons:(1)same as TLS_TASK_NELEM (2)it is no need to use two variables

Signed-off-by: yanghuatao <yanghuatao@xiaomi.com>
2023-06-14 12:00:48 +08:00
zhanghongyu d59a9ea189 inet_addr: return INADDR_NONE(-1) when input string is invalid
now:
inet_network("300.10.10.10"); return 0
inet_addr("300.10.10.10"); return 0

glibc and muscle both return INADDR_NONE or -1.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-06-13 13:31:37 +08:00
Alan Carvalho de Assis 69081a72d7 libdsp: Add average filter
This commit add average filter to DSP library
2023-06-12 08:39:38 +02:00
Petro Karashchenko 8d1a25f725 libs/libc/regex: add newline at the end of Make.defs
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-06-11 12:55:29 +08:00
Petro Karashchenko 187def2611 libs/libc/string: fix various style issues in code
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-06-11 12:55:05 +08:00
hujun5 8fe8417ffb libc/fdcheck: add fdcheck module
In embedded development environments, due to the lack of address isolation between processes,
fd may be passed between processes and lead to misuse,

We have designed an fd cross-process automatic detection tool,
fdcheck_protect returns the fd containing the pid information,
indicating that the ownership of the current fd belongs to the pid and is not allowed to be used by other processes.
fdcheck_restore will obtain the true fd and check if the ownership of the fd is legal

For ease of understanding, let's give an example where
the following information is represented in 32-bit binary format

fd        00000000 00000000 00000000 10001010
pid       00000000 00000000 00000011 01010101
ret       00000000 00000011 01010101 10001010

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2023-06-10 02:19:58 +08:00
chao an c1bcf59a85 libs/libc: fix build break on kernel mode
Signed-off-by: chao an <anchao@xiaomi.com>
2023-06-06 13:30:07 +08:00
guoshichao 441b51b706 libc/regex: provide a separate kconfig for regex
in the initial impl, the regex is depends on ALLOW_MIT_COMPONENTS, and
if other modules want to use regex, also needs to depends on
ALLOW_MIT_COMPONENTS, which is ambiguity, so we provide a seperate
kconfig option for regex: LIBC_REGEX, which is depends on
ALLOW_MIT_COMPONENTS, but is enabled by default. Thus if
ALLOW_MIT_COMPONENTS is enabled, then the LIBC_REGEX is also enabled
either automatically, and this is more clear than controlled by
ALLOW_MIT_COMPONENTS option only.

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-06-02 02:50:23 +08:00
Huang Qi 5606e77ee0 libc/wchar: Implement vswprintf
Implement vswprintf and let swprintf based on it.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2023-06-01 14:34:01 +08:00
chao an 589d4a9f8e net/semantic/parser: fix compile warning found by sparse
Reference:
https://linux.die.net/man/1/sparse

Signed-off-by: chao an <anchao@xiaomi.com>
2023-05-30 23:00:00 +08:00
chao an fb9b41221d semantic/parser: fix compile warning found by sparse
Reference:
https://linux.die.net/man/1/sparse

Signed-off-by: chao an <anchao@xiaomi.com>
2023-05-30 23:00:00 +08:00
hujun5 d70d406161 libc/fdsan: add fdsan protection for all file pointers
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2023-05-27 15:05:44 +08:00
Huang Qi 84c7a4dd69 libc.csv: Correct type of return value for strstr
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2023-05-25 20:09:27 +08:00
chao an e51ec54c02 stream/hexdump: add hexdump stream to dump binary to syslog
Signed-off-by: chao an <anchao@xiaomi.com>
2023-05-25 15:22:04 +08:00
Xiang Xiao 0203839fa1 stream: Add syslogstream implementation
which forward the output to syslog

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Signed-off-by: chao an <anchao@xiaomi.com>
2023-05-25 15:22:04 +08:00
Xiang Xiao 20ea607bd0 stream: Rename syslogstream to syslograwstream
to prepare a new stream implementation of syslog

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Signed-off-by: chao an <anchao@xiaomi.com>
2023-05-25 15:22:04 +08:00
chao an f75adacea6 stream/syslog: remove unnecessary ifdef CONFIG_SYSLOG_BUFFER
Signed-off-by: chao an <anchao@xiaomi.com>
2023-05-25 15:22:04 +08:00
chao an 0455167457 stream/syslog: use internal buffer to decoupling syslog with iob
Signed-off-by: chao an <anchao@xiaomi.com>
2023-05-24 09:53:30 +08:00
Xiang Xiao 7990f90915 Indent the define statement by two spaces
follow the code style convention

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-05-21 09:52:08 -03:00
Petro Karashchenko ede3e3e4c5 libs/libm/libmcs: add newline at the end of file
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-05-19 02:40:38 +08:00
Petro Karashchenko c70b7f6b3d nuttx: improve C89 compatibility in common code
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-05-19 02:40:38 +08:00