From b79e9ce8e126dbeb150aac5746a92709afde5a72 Mon Sep 17 00:00:00 2001 From: Alin Jerpelea Date: Tue, 31 Dec 2019 10:29:43 +0900 Subject: [PATCH 1/5] system/usbmsc: Fix accessing uninitialized pointer --- system/usbmsc/usbmsc_main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/system/usbmsc/usbmsc_main.c b/system/usbmsc/usbmsc_main.c index d4f01b2097f..089ba729d7b 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; } From f2e3e101a1b5e89bf8eb31037405937aab5d6681 Mon Sep 17 00:00:00 2001 From: Alin Jerpelea Date: Tue, 31 Dec 2019 11:20:41 +0900 Subject: [PATCH 2/5] fsutils/inifile: Fix a memory leak in inifile error case --- fsutils/inifile/inifile.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fsutils/inifile/inifile.c b/fsutils/inifile/inifile.c index 1057b930314..8c12d1a94fb 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; } } From 84b2747ad7c015681de07be61e86aa457ccbb386 Mon Sep 17 00:00:00 2001 From: Alin Jerpelea Date: Tue, 31 Dec 2019 12:37:47 +0900 Subject: [PATCH 3/5] fsutils/mksmartfs: Fix uninitialized return code --- fsutils/mksmartfs/mksmartfs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fsutils/mksmartfs/mksmartfs.c b/fsutils/mksmartfs/mksmartfs.c index 9066d136cee..180afab9bb6 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; } From a0bd4add8c3837fb537196408eced62dbc7970b8 Mon Sep 17 00:00:00 2001 From: Alin Jerpelea Date: Mon, 30 Dec 2019 14:19:47 +0900 Subject: [PATCH 4/5] system/zmodem: Fix a compile error in zmodem debug enabled --- system/zmodem/zm_send.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/zmodem/zm_send.c b/system/zmodem/zm_send.c index 6efbfbb8b3c..df236556c1e 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; } From ec60540befe0a72de81d90c6eb540fb80fa08cd8 Mon Sep 17 00:00:00 2001 From: Alin Jerpelea Date: Tue, 31 Dec 2019 13:26:48 +0900 Subject: [PATCH 5/5] 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. --- nshlib/nsh_fscmds.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/nshlib/nsh_fscmds.c b/nshlib/nsh_fscmds.c index 89db3f08beb..c55259eab14 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);