nuttx-apps/netutils
YAMAMOTO Takashi 998abe1deb netlib_parseurl.c: Fix string overruns
For EINVAL, it doesn't make sense to keep parsing.
(For E2BIG, it might make some sense.)

Found by LLVM ASan.

```
=================================================================
==81622==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6020000000f2 at pc 0x00010d2746ca bp 0x7ffee29a9980 sp 0x7ffee29a9978
READ of size 1 at 0x6020000000f2 thread T0
    #0 0x10d2746c9 in netlib_parseurl netlib_parseurl.c:121
    #1 0x10d26b293 in parseurl webclient.c:479
    #2 0x10d265e48 in webclient_perform webclient.c:690
    #3 0x10d277c5b in main main.c:210
    #4 0x7fff7a06f3d4 in start+0x0 (libdyld.dylib:x86_64+0x163d4)

0x6020000000f2 is located 0 bytes to the right of 2-byte region [0x6020000000f0,0x6020000000f2)
allocated by thread T0 here:
    #0 0x10d3996d3 in wrap_strdup+0x203 (libclang_rt.asan_osx_dynamic.dylib:x86_64+0x3e6d3)
    #1 0x10d276abe in main main.c:147
    #2 0x7fff7a06f3d4 in start+0x0 (libdyld.dylib:x86_64+0x163d4)

SUMMARY: AddressSanitizer: heap-buffer-overflow netlib_parseurl.c:121 in netlib_parseurl
Shadow bytes around the buggy address:
  0x1c03ffffffc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1c03ffffffd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1c03ffffffe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1c03fffffff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1c0400000000: fa fa fd fd fa fa fd fd fa fa 00 00 fa fa 00 00
=>0x1c0400000010: fa fa 00 fa fa fa 00 00 fa fa 00 06 fa fa[02]fa
  0x1c0400000020: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x1c0400000030: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x1c0400000040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x1c0400000050: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x1c0400000060: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==81622==ABORTING
```
2021-05-07 20:23:01 -07:00
..
chat netutils/chat/chat.c: Avoid assumping debug macro expansion 2020-12-01 07:45:05 +01:00
cjson Replace all wget with curl 2020-12-21 22:45:46 -06:00
codecs build: Replace $(TOPDIR)/Make.defs with $(APPDIR)/Make.defs 2020-07-09 15:17:37 -03:00
dhcpc netutils: dhcpc: Fix Kconfig for the usrsock 2021-04-29 01:27:47 -05:00
dhcpd netutils/dhcpd: handshake the dhcpd message with server port. 2021-03-21 20:55:32 -07:00
discover Rewritten READMEs to Markdown 2020-07-25 01:01:51 -07:00
esp8266 build: Replace $(TOPDIR)/Make.defs with $(APPDIR)/Make.defs 2020-07-09 15:17:37 -03:00
ftpc netutils/ftpc: fix incorrect comments, nxstyle 2020-12-13 11:14:43 -06:00
ftpd netutils/ftpd, examples/ftpd: code cleanup and nxstyle 2021-01-13 20:22:55 -06:00
iperf netutils/iperf: Configs were using EXAMPLES_ instead of NETUTILS_. 2021-04-21 13:43:05 -05:00
libcurl4nx build: Replace $(TOPDIR)/Make.defs with $(APPDIR)/Make.defs 2020-07-09 15:17:37 -03:00
mqttc neutils/mqttc: Update to version 1.1.5 2021-03-31 17:49:46 +01:00
netcat netcat_server: do not loop forever 2021-01-28 01:18:45 -08:00
netinit netinit: Make the default SSID and passphrase empty 2020-12-22 01:23:55 -06:00
netlib netlib_parseurl.c: Fix string overruns 2021-05-07 20:23:01 -07:00
ntpclient ntpclient: Add ntpcstatus() api to query ntpc status programatically 2021-02-20 01:30:55 -08:00
ping Change all files come from Xiaomi/Pinecone to Apache License 2.0 2020-08-23 15:44:32 -06:00
pppd build: Replace $(TOPDIR)/Make.defs with $(APPDIR)/Make.defs 2020-07-09 15:17:37 -03:00
smtp build: Replace $(TOPDIR)/Make.defs with $(APPDIR)/Make.defs 2020-07-09 15:17:37 -03:00
telnetc build: Replace $(TOPDIR)/Make.defs with $(APPDIR)/Make.defs 2020-07-09 15:17:37 -03:00
telnetd dhcpd/telnet: don't need to dupcalite listen socket when task_create 2021-03-19 08:21:27 +09:00
tftpc netutils/tftpc: typos, nxstyle 2021-01-19 19:51:33 +01:00
thttpd thttpd: add THTTPD_NFILE_DESCRIPTORS limits instead of NFILE_DESCRIPTORS 2021-03-16 07:56:45 -07:00
usrsock_rpmsg usrsock/server: replace the wakeup source to eventfd 2021-04-21 09:53:40 -05:00
webclient netutils/webclient: Fixed socket descriptor leak. 2021-05-03 16:44:28 +09:00
webserver httpd: expose http_send_headers to be used in CGI handlers 2021-03-30 22:27:49 -05:00
xmlrpc build: Replace $(TOPDIR)/Make.defs with $(APPDIR)/Make.defs 2020-07-09 15:17:37 -03:00
.gitignore build: Remve the unnecessary .gitignore 2020-05-23 15:56:35 +01:00
Make.defs Make.defs: Use complete include path 2020-02-19 12:56:10 -06:00
Makefile Rearrange to eliminate Kmenu files 2016-06-09 08:59:16 -06:00
README.md Rewritten READMEs to Markdown 2020-07-25 01:01:51 -07:00

Network Utilities

Contents

  • uIP Applications
  • Other Network Applications
  • Tips for Using Telnetd
  • Tips for Using DHCPC

uIP Applications

This directory contains most of the network applications contained under the uIP-1.0 apps directory. As the uIP apps/README.md says, these applications are not all heavily tested. These uIP-based apps include:

  • dhcpc Dynamic Host Configuration Protocol (DHCP) client. See apps/include/netutils/dhcpc.h for interface information.

  • smtp Simple Mail Transfer Protocol (SMTP) client. See apps/include/netutils/smtp.h for interface information.

  • webclient HTTP web client. See apps/include/netutils/webclient.h for interface information.

  • webserver HTTP web server. See apps/include/netutils/httpd.h for interface information.

You may find additional information on these apps in the uIP forum accessible through: http://www.sics.se/~adam/uip/index.php/Main_Page. Some of these (such as the uIP web server) have grown some additional functionality due primarily to NuttX user contributions.

Other Network Applications

Additional applications that were not part of uIP (but which are highly influenced by uIP) include:

  • dhcpd Dynamic Host Configuration Protocol (DHCP) server. See apps/include/netutils/dhcpd.h for interface information.

  • discover This daemon is useful for discovering devices in local networks, especially with DHCP configured devices. It listens for UDP broadcasts which also can include a device class so that groups of devices can be discovered. It is also possible to address all classes with a kind of broadcast discover. (Contributed by Max Holtzberg).

  • esp8266 An ESP8266 networking layer contributed by Pierre-Noel Bouteville.

  • json cJSON is an ultra-lightweight, portable, single-file, simple-as-can-be ANSI-C compliant JSON parser, under MIT license. Embeddable Lightweight XML-RPC Server discussed at http://www.drdobbs.com/web-development/an-embeddable-lightweight-xml-rpc-server/184405364.

    This code was taken from http://sourceforge.net/projects/cjson/ and adapted for NuttX by Darcy Gong.

  • tftpc TFTP client. See apps/include/netutils/tftp.h for interface information.

  • telnetc This is a port of libtelnet to NuttX. This is a public domain Telnet client library available from https://github.com/seanmiddleditch/libtelnet modified for use with NuttX. Original Authors: Sean Middleditch sean@sourcemud.org, Jack Kelly endgame.dos@gmail.com and Katherine Flavel kate@elide.org

  • telnetd TELNET server. This is the Telnet logic adapted from uIP and generalized for use as the front end to any shell. The telnet daemon creates sessions that are wrapped as character devices and mapped to stdin, stdout and stderr. Now the telnet session can be inherited by spawned tasks.

  • ftpc FTP client. See apps/include/netutils/ftpc.h for interface information.

  • ftpd FTP server. See apps/include/netutils/ftpd.h for interface information.

  • ntpclient This is a fragmentary NTP client. It neither well-tested nor mature nor complete at this point in time.

  • thttpd This is a port of Jef Poskanzer's THTTPD HTPPD server. See http://acme.com/software/thttpd/ for general THTTPD information. See apps/include/netutils/thttpd.h for interface information. Applications using this thttpd will need to provide the following definitions in the defconfig file to select the appropriate netutils libraries:

    CONFIG_NETUTILS_NETLIB=y
    CONFIG_NETUTILS_THTTPD=y
    
  • xmlrpc The Embeddable Lightweight XML-RPC Server discussed at http://www.drdobbs.com/web-development/an-embeddable-lightweight-xml-rpc-server/184405364

  • ping This is an unfinished implementation of ping and ping6 using raw sockets. It is not yet hooked into the configuration or build systems.

    Current ping/ping6 logic in NSH makes illegal calls into the OS in order to implement ping/ping6. One correct implementation would be to use raw sockets to implement ping/ping6 as a user application. This is a first cut at such an implementation.

Tips for Using Telnetd

Telnetd is set up to be the front end for a shell. The primary use of Telnetd in NuttX is to support the NuttShell (NSH) Telnet front end. See apps/include/netutils/telnetd.h for information about how to incorporate Telnetd into your custom applications.

To enable and link the Telnetd daemon, you need to include the following in in your defconfig file:

CONFIG_NETUTILS_NETLIB=y
CONFIG_NETUTILS_TELNETD=y

Also if the Telnet console is enabled, make sure that you have the following set in the NuttX configuration file or else the performance will be very bad (because there will be only one character per TCP transfer):

  • CONFIG_STDIO_BUFFER_SIZE Some value >= 64.
  • CONFIG_STDIO_LINEBUFFER=y Since Telnetd is line oriented, line buffering is optimal.

Tips for Using DHCPC

If you use DHCPC/D, then some special configuration network options are required. These include:

  • CONFIG_NET=y
  • CONFIG_NET_UDP=y UDP support is required for DHCP (as well as various other UDP-related configuration settings).
  • CONFIG_NET_BROADCAST=y UDP broadcast support is needed.
  • CONFIG_NET_ETH_PKTSIZE=650 or larger. The client must be prepared to receive DHCP messages of up to 576 bytes (excluding Ethernet, IP or UDP headers and FCS). Note: Note that the actual MTU setting will depend upon the specific link protocol. Here Ethernet is indicated.