diff --git a/examples/lp503x/lp503x_main.c b/examples/lp503x/lp503x_main.c index 4ab99803fd5..57e3de751ba 100644 --- a/examples/lp503x/lp503x_main.c +++ b/examples/lp503x/lp503x_main.c @@ -625,20 +625,26 @@ static int lp503x_cmd_help(FAR char *parg) int main(int argc, FAR char *argv[]) { + FAR char *buffer; + FAR char *cmd; + FAR char *arg; bool running; - char buffer[LINE_MAX]; int len; int x; - char *cmd; - char *arg; fd = open(CONFIG_EXAMPLES_LP503X_DEVPATH, O_CREAT); if (fd < 0) { fprintf(stderr, "ERROR: Failed to open %s: %d\n", CONFIG_EXAMPLES_LP503X_DEVPATH, errno); - close(fd); - return ENODEV; + return -ENODEV; + } + + buffer = lib_get_tempbuffer(LINE_MAX); + if (buffer == NULL) + { + close(fd); + return -ENOMEM; } running = true; @@ -649,7 +655,7 @@ int main(int argc, FAR char *argv[]) /* read a line from the terminal */ - len = readline_stream(buffer, sizeof(buffer), + len = readline_stream(buffer, LINE_MAX, stdin, stdout); buffer[len] = '\0'; if (len > 0) @@ -715,6 +721,7 @@ int main(int argc, FAR char *argv[]) } } + lib_put_tempbuffer(buffer); close(fd); return 0; diff --git a/netutils/rexec/rexec.c b/netutils/rexec/rexec.c index 01c8000bf5d..55f6c8547e7 100644 --- a/netutils/rexec/rexec.c +++ b/netutils/rexec/rexec.c @@ -155,9 +155,10 @@ static int do_rexec(FAR struct rexec_arg_s *arg) int main(int argc, FAR char **argv) { - char cmd[LINE_MAX]; struct rexec_arg_s arg; + FAR char *cmd; int option; + int ret; int i; memset(&arg, 0, sizeof(arg)); @@ -202,13 +203,21 @@ int main(int argc, FAR char **argv) usage(argv[0]); } + cmd = lib_get_tempbuffer(LINE_MAX); + if (cmd == NULL) + { + return -ENOMEM; + } + cmd[0] = '\0'; for (i = optind; i < argc; i++) { - strlcat(cmd, argv[i], sizeof(cmd)); - strlcat(cmd, " ", sizeof(cmd)); + strlcat(cmd, argv[i], LINE_MAX); + strlcat(cmd, " ", LINE_MAX); } arg.command = cmd; - return do_rexec(&arg); + ret = do_rexec(&arg); + lib_put_tempbuffer(cmd); + return ret; } diff --git a/nshlib/nsh_mmcmds.c b/nshlib/nsh_mmcmds.c index 81427a00baa..9cbd01ce030 100644 --- a/nshlib/nsh_mmcmds.c +++ b/nshlib/nsh_mmcmds.c @@ -26,6 +26,7 @@ #include +#include #include #include "nsh.h" @@ -58,9 +59,18 @@ int cmd_free(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv) int cmd_memdump(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv) { - char arg[LINE_MAX] = ""; + FAR char *arg; + int ret; int i; + arg = lib_get_tempbuffer(LINE_MAX); + if (arg == NULL) + { + return -ENOMEM; + } + + arg[0] = '\0'; + if (argc == 1) { strlcpy(arg, "used", LINE_MAX); @@ -68,8 +78,10 @@ int cmd_memdump(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv) else if (argc >= 2 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "help") == 0)) { - return nsh_catfile(vtbl, argv[0], - CONFIG_NSH_PROC_MOUNTPOINT "/memdump"); + ret = nsh_catfile(vtbl, argv[0], + CONFIG_NSH_PROC_MOUNTPOINT "/memdump"); + lib_put_tempbuffer(arg); + return ret; } else { @@ -83,8 +95,10 @@ int cmd_memdump(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv) } } - return nsh_writefile(vtbl, argv[0], arg, strlen(arg), - CONFIG_NSH_PROC_MOUNTPOINT "/memdump"); + ret = nsh_writefile(vtbl, argv[0], arg, strlen(arg), + CONFIG_NSH_PROC_MOUNTPOINT "/memdump"); + lib_put_tempbuffer(arg); + return ret; } #endif /* !CONFIG_NSH_DISABLE_MEMDUMP && NSH_HAVE_WRITEFILE */ diff --git a/nshlib/nsh_parse.c b/nshlib/nsh_parse.c index d60e4c76871..e4a63540705 100644 --- a/nshlib/nsh_parse.c +++ b/nshlib/nsh_parse.c @@ -2696,6 +2696,14 @@ static int nsh_parse_command(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline) FAR char *sh_argv[4]; FAR char *sh_arg2; + sh_arg2 = lib_get_tempbuffer(LINE_MAX); + if (sh_arg2 == NULL) + { + nsh_error(vtbl, g_fmtcmdoutofmemory, cmd); + ret = -ENOMEM; + goto dynlist_free; + } + if (argv[argc][g_pipeline1_len]) { arg = &argv[argc][g_pipeline1_len]; @@ -2708,6 +2716,7 @@ static int nsh_parse_command(FAR struct nsh_vtbl_s *vtbl, FAR char *cmdline) if (!arg) { nsh_error(vtbl, g_fmtarginvalid, cmd); + lib_put_tempbuffer(sh_arg2); ret = ERROR; goto dynlist_free; } diff --git a/nshlib/nsh_timcmds.c b/nshlib/nsh_timcmds.c index 732bb512e9a..a3e9863b869 100644 --- a/nshlib/nsh_timcmds.c +++ b/nshlib/nsh_timcmds.c @@ -26,6 +26,7 @@ #include +#include #include #include #include @@ -552,7 +553,7 @@ int cmd_timedatectl(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv) #ifndef CONFIG_NSH_DISABLE_WATCH int cmd_watch(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv) { - char buffer[LINE_MAX]; + FAR char *buffer; int interval = 2; int count = -1; FAR char *cmd; @@ -593,6 +594,13 @@ int cmd_watch(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv) count = INT_MAX; } + buffer = lib_get_tempbuffer(LINE_MAX); + if (buffer == NULL) + { + nsh_error(vtbl, g_fmtcmdfailed, argv[0], cmd, ENOMEM); + return -ENOMEM; + } + for (i = 0; i < count; i++) { strlcpy(buffer, cmd, LINE_MAX); @@ -600,12 +608,14 @@ int cmd_watch(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv) if (ret < 0) { nsh_error(vtbl, g_fmtcmdfailed, argv[0], cmd, NSH_ERRNO); + lib_put_tempbuffer(buffer); return ERROR; } sleep(interval); } + lib_put_tempbuffer(buffer); return OK; } #endif diff --git a/system/nxcamera/nxcamera_main.c b/system/nxcamera/nxcamera_main.c index 754f12e1d2f..95f1c7a8036 100644 --- a/system/nxcamera/nxcamera_main.c +++ b/system/nxcamera/nxcamera_main.c @@ -398,7 +398,7 @@ static int nxcamera_cmd_help(FAR struct nxcamera_s *pcam, FAR char *parg) int main(int argc, FAR char *argv[]) { - char buffer[LINE_MAX]; + FAR char *buffer; int len; int x; bool running = true; @@ -422,6 +422,14 @@ int main(int argc, FAR char *argv[]) return -ENOMEM; } + buffer = lib_get_tempbuffer(LINE_MAX); + if (buffer == NULL) + { + nxcamera_release(pcam); + printf("Error: lib_get_tempbuffer failed\n"); + return -ENOMEM; + } + /* Loop until the user exits */ while (running) @@ -433,7 +441,7 @@ int main(int argc, FAR char *argv[]) /* Read a line from the terminal */ - len = readline_stream(buffer, sizeof(buffer), + len = readline_stream(buffer, LINE_MAX, stdin, stdout); if (len > 0) { @@ -495,6 +503,7 @@ int main(int argc, FAR char *argv[]) /* Release the NxCamera context */ nxcamera_release(pcam); + lib_put_tempbuffer(buffer); return OK; } diff --git a/system/nxlooper/nxlooper_main.c b/system/nxlooper/nxlooper_main.c index 710fb8a77a8..8ba0130364a 100644 --- a/system/nxlooper/nxlooper_main.c +++ b/system/nxlooper/nxlooper_main.c @@ -502,7 +502,7 @@ static int nxlooper_cmd_help(FAR struct nxlooper_s *plooper, char *parg) int main(int argc, FAR char *argv[]) { - char buffer[LINE_MAX]; + FAR char *buffer; int len; int x; int running; @@ -523,6 +523,14 @@ int main(int argc, FAR char *argv[]) return -ENOMEM; } + buffer = lib_get_tempbuffer(LINE_MAX); + if (buffer == NULL) + { + nxlooper_release(plooper); + printf("Error: lib_get_tempbuffer failed\n"); + return -ENOMEM; + } + /* Loop until the user exits */ running = TRUE; @@ -535,7 +543,7 @@ int main(int argc, FAR char *argv[]) /* Read a line from the terminal */ - len = readline_stream(buffer, sizeof(buffer), + len = readline_stream(buffer, LINE_MAX, stdin, stdout); if (len > 0) { @@ -597,6 +605,7 @@ int main(int argc, FAR char *argv[]) /* Release the NxLooper context */ nxlooper_release(plooper); + lib_put_tempbuffer(buffer); return OK; } diff --git a/system/nxplayer/nxplayer_main.c b/system/nxplayer/nxplayer_main.c index daeed9477b2..d85fa51e7d0 100644 --- a/system/nxplayer/nxplayer_main.c +++ b/system/nxplayer/nxplayer_main.c @@ -739,7 +739,7 @@ static int nxplayer_cmd_help(FAR struct nxplayer_s *pplayer, char *parg) int main(int argc, FAR char *argv[]) { - char buffer[LINE_MAX]; + FAR char *buffer; int len; int x; int running; @@ -760,6 +760,14 @@ int main(int argc, FAR char *argv[]) return -ENOMEM; } + buffer = lib_get_tempbuffer(LINE_MAX); + if (buffer == NULL) + { + nxplayer_release(pplayer); + printf("Error: lib_get_tempbuffer failed\n"); + return -ENOMEM; + } + /* Loop until the user exits */ running = TRUE; @@ -772,7 +780,7 @@ int main(int argc, FAR char *argv[]) /* Read a line from the terminal */ - len = readline_stream(buffer, sizeof(buffer), + len = readline_stream(buffer, LINE_MAX, stdin, stdout); if (len > 0) { @@ -841,6 +849,7 @@ int main(int argc, FAR char *argv[]) /* Release the NxPlayer context */ nxplayer_release(pplayer); + lib_put_tempbuffer(buffer); return OK; } diff --git a/system/nxrecorder/nxrecorder_main.c b/system/nxrecorder/nxrecorder_main.c index 5b649d5321f..c7303012790 100644 --- a/system/nxrecorder/nxrecorder_main.c +++ b/system/nxrecorder/nxrecorder_main.c @@ -531,7 +531,7 @@ static int nxrecorder_cmd_help(FAR struct nxrecorder_s *precorder, int main(int argc, FAR char *argv[]) { - char buffer[LINE_MAX]; + FAR char *buffer; int len; int x; int running; @@ -552,6 +552,14 @@ int main(int argc, FAR char *argv[]) return -ENOMEM; } + buffer = lib_get_tempbuffer(LINE_MAX); + if (buffer == NULL) + { + nxrecorder_release(precorder); + printf("Error: lib_get_tempbuffer failed\n"); + return -ENOMEM; + } + /* Loop until the user exits */ running = TRUE; @@ -564,7 +572,7 @@ int main(int argc, FAR char *argv[]) /* Read a line from the terminal */ - len = readline_stream(buffer, sizeof(buffer), + len = readline_stream(buffer, LINE_MAX, stdin, stdout); if (len > 0) { @@ -633,6 +641,7 @@ int main(int argc, FAR char *argv[]) /* Release the NxRecorder context */ nxrecorder_release(precorder); + lib_put_tempbuffer(buffer); return OK; } diff --git a/system/taskset/taskset.c b/system/taskset/taskset.c index bae0246a9b3..52b93dfe976 100644 --- a/system/taskset/taskset.c +++ b/system/taskset/taskset.c @@ -82,7 +82,7 @@ static bool get_cpuset(const char *arg, cpu_set_t *cpu_set) int main(int argc, FAR char *argv[]) { - char command[LINE_MAX]; + FAR char *command; int exitcode; int option; int pid = -1; @@ -90,6 +90,12 @@ int main(int argc, FAR char *argv[]) int rc; int i; + command = lib_get_tempbuffer(LINE_MAX); + if (command == NULL) + { + return -ENOMEM; + } + command[0] = '\0'; CPU_ZERO(&cpuset); @@ -158,8 +164,8 @@ int main(int argc, FAR char *argv[]) for (i = 0; i < argc - 2; i++) { - strlcat(command, argv[i + 2], sizeof(command)); - strlcat(command, " ", sizeof(command)); + strlcat(command, argv[i + 2], LINE_MAX); + strlcat(command, " ", LINE_MAX); } sched_setaffinity(gettid(), sizeof(cpu_set_t), &cpuset); @@ -168,8 +174,10 @@ int main(int argc, FAR char *argv[]) } errout: + lib_put_tempbuffer(command); return EXIT_SUCCESS; errout_with_usage: + lib_put_tempbuffer(command); show_usage(argv[0], exitcode); return exitcode; /* Not reachable */ } diff --git a/system/trace/trace.c b/system/trace/trace.c index f4a5454a40a..986b7b135ba 100644 --- a/system/trace/trace.c +++ b/system/trace/trace.c @@ -229,7 +229,7 @@ static int trace_cmd_dump(FAR const char *name, int index, int argc, static int trace_cmd_cmd(FAR const char *name, int index, int argc, FAR char **argv, int notectlfd) { - char command[LINE_MAX]; + FAR char *command; bool changed; bool cont = false; @@ -253,11 +253,17 @@ static int trace_cmd_cmd(FAR const char *name, int index, int argc, return ERROR; } + command = lib_get_tempbuffer(LINE_MAX); + if (command == NULL) + { + return -ENOMEM; + } + command[0] = '\0'; while (index < argc) { - strlcat(command, argv[index], sizeof(command)); - strlcat(command, " ", sizeof(command)); + strlcat(command, argv[index], LINE_MAX); + strlcat(command, " ", LINE_MAX); index++; } @@ -273,6 +279,7 @@ static int trace_cmd_cmd(FAR const char *name, int index, int argc, changed = notectl_enable(name, true, notectlfd); system(command); + lib_put_tempbuffer(command); if (changed) {