From cef306e33569d78b57a9e9341b30eb4464b14344 Mon Sep 17 00:00:00 2001 From: Juha Niskanen Date: Wed, 29 Aug 2018 06:18:30 -0600 Subject: [PATCH] apps/nshlib/nsh_console.c: Do not dereference NULL 'pstate' --- nshlib/nsh_console.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/nshlib/nsh_console.c b/nshlib/nsh_console.c index 1a22f0a66..36a72782a 100644 --- a/nshlib/nsh_console.c +++ b/nshlib/nsh_console.c @@ -440,22 +440,28 @@ FAR struct console_stdio_s *nsh_newconsole(void) /* Initialize the call table */ #ifndef CONFIG_NSH_DISABLEBG - pstate->cn_vtbl.clone = nsh_consoleclone; - pstate->cn_vtbl.release = nsh_consolerelease; + pstate->cn_vtbl.clone = nsh_consoleclone; + pstate->cn_vtbl.release = nsh_consolerelease; +#endif + pstate->cn_vtbl.write = nsh_consolewrite; + pstate->cn_vtbl.output = nsh_consoleoutput; + pstate->cn_vtbl.linebuffer = nsh_consolelinebuffer; + pstate->cn_vtbl.exit = nsh_consoleexit; + +#ifndef CONFIG_NSH_DISABLESCRIPT + /* Set the initial option flags */ + + pstate->cn_vtbl.np.np_flags = NSH_NP_SET_OPTIONS_INIT; #endif - pstate->cn_vtbl.write = nsh_consolewrite; - pstate->cn_vtbl.output = nsh_consoleoutput; - pstate->cn_vtbl.linebuffer = nsh_consolelinebuffer; - pstate->cn_vtbl.exit = nsh_consoleexit; #if CONFIG_NFILE_STREAMS > 0 - pstate->cn_vtbl.redirect = nsh_consoleredirect; - pstate->cn_vtbl.undirect = nsh_consoleundirect; + pstate->cn_vtbl.redirect = nsh_consoleredirect; + pstate->cn_vtbl.undirect = nsh_consoleundirect; /* (Re-) open the console input device */ #ifdef CONFIG_NSH_ALTCONDEV - pstate->cn_confd = open(CONFIG_NSH_CONDEV, O_RDWR); + pstate->cn_confd = open(CONFIG_NSH_CONDEV, O_RDWR); if (pstate->cn_confd < 0) { free(pstate); @@ -475,16 +481,10 @@ FAR struct console_stdio_s *nsh_newconsole(void) /* Initialize the output stream */ - pstate->cn_outfd = OUTFD(pstate); - pstate->cn_outstream = OUTSTREAM(pstate); + pstate->cn_outfd = OUTFD(pstate); + pstate->cn_outstream = OUTSTREAM(pstate); #endif } -#ifndef CONFIG_NSH_DISABLESCRIPT - /* Set the initial option flags */ - - pstate->cn_vtbl.np.np_flags = NSH_NP_SET_OPTIONS_INIT; -#endif - return pstate; }