diff options
author | Aaron Nyholm <aaron.nyholm@southerninnovation.com> | 2023-05-17 10:03:47 +1000 |
---|---|---|
committer | Joel Sherrill <joel@rtems.org> | 2023-05-17 13:41:44 -0500 |
commit | c2913ec414b80c281618a30357ebb79761f49c6a (patch) | |
tree | e8081d63f5340fbc625599a6b694d52744abef98 /cpukit | |
parent | bsps/aarch64: Fix 128bit q register print bug (diff) | |
download | rtems-c2913ec414b80c281618a30357ebb79761f49c6a.tar.bz2 |
libmisc/shell: Fix file pointer leak and improved input data sanitation.
Coverity #1530126
Coverity #1530125
Diffstat (limited to 'cpukit')
-rw-r--r-- | cpukit/libmisc/shell/main_flashdev.c | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/cpukit/libmisc/shell/main_flashdev.c b/cpukit/libmisc/shell/main_flashdev.c index 495373235f..ca2454b33c 100644 --- a/cpukit/libmisc/shell/main_flashdev.c +++ b/cpukit/libmisc/shell/main_flashdev.c @@ -78,6 +78,15 @@ static int rtems_flashdev_shell_main( int argc, char *argv[] ) { for (i = 1; i < argc; ++i) { if (argv[i][0] == '-') { + /* + * Check that a path to flashdev has been provided before running + * command. + */ + if (dev_path == NULL) { + printf("Please input FLASH_DEV_PATH before instruction\n"); + return 1; + } + /* Run command */ switch (argv[i][1]) { case ('r'): /* Read */ @@ -112,7 +121,6 @@ static int rtems_flashdev_shell_main( int argc, char *argv[] ) { printf(rtems_flashdev_shell_usage); break; } - } else if (dev_path == NULL) { dev_path = argv[i]; } else { @@ -145,10 +153,6 @@ int flashdev_shell_read( printf("Missing argument\n"); return -1; } - if (dev_path == NULL) { - printf("Please input FLASH_DEV_PATH before instruction\n"); - return 1; - } /* Get arguments */ errno = 0; @@ -181,6 +185,7 @@ int flashdev_shell_read( buffer = calloc((bytes + bytes%4), 1); if (buffer == NULL) { printf("Failed to allocate read buffer\n"); + close(fd); return -1; } @@ -230,10 +235,6 @@ int flashdev_shell_write( printf("Missing argument\n"); return -1; } - if (dev_path == NULL) { - printf("Please input FLASH_DEV_PATH before instruction\n"); - return 1; - } /* Get arguments */ errno = 0; @@ -337,10 +338,6 @@ int flashdev_shell_erase( printf("Missing argument\n"); return -1; } - if (dev_path == NULL) { - printf("Please input FLASH_DEV_PATH before instruction\n"); - return 1; - } /* Get arguments */ errno = 0; @@ -546,10 +543,6 @@ static int flashdev_shell_page( printf("Missing argument\n"); return -1; } - if (dev_path == NULL) { - printf("Please input FLASH_DEV_PATH before instruction\n"); - return 1; - } /* Get arguments */ errno = 0; |