You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/01/07 14:42:50 UTC

[incubator-nuttx-apps] branch pr6 updated: various fixes (#6)

This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch pr6
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git


The following commit(s) were added to refs/heads/pr6 by this push:
     new 590cebc  various fixes (#6)
590cebc is described below

commit 590cebc2d35b423dfee70b0c7b7f7aef6bd2c419
Author: Alin Jerpelea <al...@sony.com>
AuthorDate: Tue Jan 7 16:42:41 2020 +0200

    various fixes (#6)
    
    * system/usbmsc: Fix accessing uninitialized pointer
    * fsutils/inifile: Fix a memory leak in inifile error case
    * fsutils/mksmartfs: Fix uninitialized return code
    * system/zmodem: Fix a compile error in zmodem debug enabled
    * nshlib/nsh_fscmds.c: Add syntax check to cp command
    
    If the destication of NutShell cp command is the same with the source,
    it may cause the file corruption. Add the syntax check of argument to
    avoid this problem.
---
 fsutils/inifile/inifile.c     | 1 +
 fsutils/mksmartfs/mksmartfs.c | 1 +
 nshlib/nsh_fscmds.c           | 8 ++++++++
 system/usbmsc/usbmsc_main.c   | 7 +++++--
 system/zmodem/zm_send.c       | 2 +-
 5 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/fsutils/inifile/inifile.c b/fsutils/inifile/inifile.c
index 1057b93..8c12d1a 100644
--- a/fsutils/inifile/inifile.c
+++ b/fsutils/inifile/inifile.c
@@ -527,6 +527,7 @@ INIHANDLE inifile_initialize(FAR const char *inifile_name)
   else
     {
       inidbg("ERROR: Could not open \"%s\"\n", inifile_name);
+      free(priv);
       return (INIHANDLE)NULL;
     }
 }
diff --git a/fsutils/mksmartfs/mksmartfs.c b/fsutils/mksmartfs/mksmartfs.c
index 9066d13..180afab 100644
--- a/fsutils/mksmartfs/mksmartfs.c
+++ b/fsutils/mksmartfs/mksmartfs.c
@@ -173,6 +173,7 @@ int mksmartfs(FAR const char *pathname, uint16_t sectorsize)
   fd = open(pathname, O_RDWR);
   if (fd < 0)
     {
+      ret = -ENOENT;
       goto errout;
     }
 
diff --git a/nshlib/nsh_fscmds.c b/nshlib/nsh_fscmds.c
index 89db3f0..c55259e 100644
--- a/nshlib/nsh_fscmds.c
+++ b/nshlib/nsh_fscmds.c
@@ -581,6 +581,14 @@ int cmd_cp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
         }
     }
 
+  /* Check if the destination does not match the source */
+
+  if (strcmp(destpath, srcpath) == 0)
+    {
+      nsh_error(vtbl, g_fmtsyntax, argv[0]);
+      goto errout_with_allocpath;
+    }
+
   /* Now open the destination */
 
   wrfd = open(destpath, oflags, 0666);
diff --git a/system/usbmsc/usbmsc_main.c b/system/usbmsc/usbmsc_main.c
index d4f01b2..089ba72 100644
--- a/system/usbmsc/usbmsc_main.c
+++ b/system/usbmsc/usbmsc_main.c
@@ -435,7 +435,7 @@ static void usbmsc_disconnect(FAR void *handle)
 int main(int argc, FAR char *argv[])
 {
   struct boardioc_usbdev_ctrl_s ctrl;
-  FAR void *handle;
+  FAR void *handle = NULL;
   int ret;
 
   /* If this program is implemented as the NSH 'msconn' command, then we
@@ -495,7 +495,10 @@ int main(int argc, FAR char *argv[])
   if (ret < 0)
     {
       printf("mcsonn_main: usbmsc_configure failed: %d\n", -ret);
-      usbmsc_disconnect(handle);
+      if (handle)
+        {
+          usbmsc_disconnect(handle);
+        }
       return EXIT_FAILURE;
     }
 
diff --git a/system/zmodem/zm_send.c b/system/zmodem/zm_send.c
index 6efbfbb..df23655 100644
--- a/system/zmodem/zm_send.c
+++ b/system/zmodem/zm_send.c
@@ -494,7 +494,7 @@ static int zms_zrinit(FAR struct zm_state_s *pzm)
   else
 #  endif
     {
-      zmdbg("ZMS_STATE %d->%d\n", pzm->state, );
+      zmdbg("ZMS_STATE %d->%d\n", pzm->state, ZMS_DONE);
       pzm->state = ZMS_DONE;
       return ZM_XFRDONE;
     }