Skip to content

Commit 590cebc

Browse files
jerpeleapatacongo
authored andcommitted
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.
1 parent 74ba8ff commit 590cebc

File tree

5 files changed

+16
-3
lines changed

5 files changed

+16
-3
lines changed

fsutils/inifile/inifile.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ INIHANDLE inifile_initialize(FAR const char *inifile_name)
527527
else
528528
{
529529
inidbg("ERROR: Could not open \"%s\"\n", inifile_name);
530+
free(priv);
530531
return (INIHANDLE)NULL;
531532
}
532533
}

fsutils/mksmartfs/mksmartfs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ int mksmartfs(FAR const char *pathname, uint16_t sectorsize)
173173
fd = open(pathname, O_RDWR);
174174
if (fd < 0)
175175
{
176+
ret = -ENOENT;
176177
goto errout;
177178
}
178179

nshlib/nsh_fscmds.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,14 @@ int cmd_cp(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
581581
}
582582
}
583583

584+
/* Check if the destination does not match the source */
585+
586+
if (strcmp(destpath, srcpath) == 0)
587+
{
588+
nsh_error(vtbl, g_fmtsyntax, argv[0]);
589+
goto errout_with_allocpath;
590+
}
591+
584592
/* Now open the destination */
585593

586594
wrfd = open(destpath, oflags, 0666);

system/usbmsc/usbmsc_main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ static void usbmsc_disconnect(FAR void *handle)
435435
int main(int argc, FAR char *argv[])
436436
{
437437
struct boardioc_usbdev_ctrl_s ctrl;
438-
FAR void *handle;
438+
FAR void *handle = NULL;
439439
int ret;
440440

441441
/* If this program is implemented as the NSH 'msconn' command, then we
@@ -495,7 +495,10 @@ int main(int argc, FAR char *argv[])
495495
if (ret < 0)
496496
{
497497
printf("mcsonn_main: usbmsc_configure failed: %d\n", -ret);
498-
usbmsc_disconnect(handle);
498+
if (handle)
499+
{
500+
usbmsc_disconnect(handle);
501+
}
499502
return EXIT_FAILURE;
500503
}
501504

system/zmodem/zm_send.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ static int zms_zrinit(FAR struct zm_state_s *pzm)
494494
else
495495
# endif
496496
{
497-
zmdbg("ZMS_STATE %d->%d\n", pzm->state, );
497+
zmdbg("ZMS_STATE %d->%d\n", pzm->state, ZMS_DONE);
498498
pzm->state = ZMS_DONE;
499499
return ZM_XFRDONE;
500500
}

0 commit comments

Comments
 (0)