[rtems commit] tftpfs: Some bug fixes

Sebastian Huber sebh at rtems.org
Fri Dec 21 06:51:10 UTC 2018


Module:    rtems
Branch:    master
Commit:    10135fab5d94fb856e07cdf0c80fd476399f5ed2
Changeset: http://git.rtems.org/rtems/commit/?id=10135fab5d94fb856e07cdf0c80fd476399f5ed2

Author:    Thomas Dörfler <thomas.doerfler at embedded-brains.de>
Date:      Thu Dec 20 14:26:50 2018 +0100

tftpfs: Some bug fixes

Fix for:

- tftpfs did not mount, when device field in mount entry is empty

- tftpfs needs to allocate fs structure before it fills it (avoid use of
  uninitialized pointer)

- tftpfs needs to skip initial slash before hostname

---

 cpukit/libnetworking/lib/tftpDriver.c | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/cpukit/libnetworking/lib/tftpDriver.c b/cpukit/libnetworking/lib/tftpDriver.c
index 514f931..7cbb402 100644
--- a/cpukit/libnetworking/lib/tftpDriver.c
+++ b/cpukit/libnetworking/lib/tftpDriver.c
@@ -186,21 +186,28 @@ int rtems_tftpfs_initialize(
 {
   const char *device = mt_entry->dev;
   size_t devicelen = strlen (device);
-  tftpfs_info_t *fs;
+  tftpfs_info_t *fs = NULL;
   char *root_path;
 
-  if (devicelen == 0)
-      rtems_set_errno_and_return_minus_one (ENXIO);
-
-  fs = malloc (sizeof (*fs));
-  root_path = malloc (devicelen + 2);
-  if (root_path == NULL || fs == NULL)
+  if (devicelen == 0) {
+    root_path = malloc (1);
+    if (root_path == NULL)
+      goto error;
+    root_path [0] = '\0';
+  }
+  else {
+    root_path = malloc (devicelen + 2);
+    if (root_path == NULL)
       goto error;
 
-  root_path = memcpy (root_path, device, devicelen);
-  root_path [devicelen] = '/';
-  root_path [devicelen + 1] = '\0';
+    root_path = memcpy (root_path, device, devicelen);
+    root_path [devicelen] = '/';
+    root_path [devicelen + 1] = '\0';
+  }
 
+  fs = malloc (sizeof (*fs));
+  if (fs == NULL)
+    goto error;
   fs->flags = 0;
   fs->nStreams = 0;
   fs->tftpStreams = 0;
@@ -538,6 +545,9 @@ static int rtems_tftp_open_worker(
     /*
      * Extract the host name component
      */
+    if (*full_path_name == '/')
+      full_path_name++;
+
     hostname = full_path_name;
     cp1 = strchr (full_path_name, ':');
     if (!cp1) {




More information about the vc mailing list