[rtems commit] Avoid NULL pointer access

Sebastian Huber sebh at rtems.org
Mon Feb 13 16:04:19 UTC 2012


Module:    rtems
Branch:    master
Commit:    002affcfbe471fafa7552f4801f39864c0f73038
Changeset: http://git.rtems.org/rtems/commit/?id=002affcfbe471fafa7552f4801f39864c0f73038

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Mon Feb 13 16:40:54 2012 +0100

Avoid NULL pointer access

---

 cpukit/libmisc/shell/shell_getprompt.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/cpukit/libmisc/shell/shell_getprompt.c b/cpukit/libmisc/shell/shell_getprompt.c
index 08c628b..357bb1a 100644
--- a/cpukit/libmisc/shell/shell_getprompt.c
+++ b/cpukit/libmisc/shell/shell_getprompt.c
@@ -37,13 +37,15 @@ void rtems_shell_get_prompt(
   size_t             size
 )
 {
-  char curdir[256];
+  char buf[256];
+  char *cwd;
 
   /* XXX: show_prompt user adjustable */
-  getcwd(curdir,sizeof(curdir));
+  cwd = getcwd(buf,sizeof(buf));
+  cwd = cwd != NULL ? cwd : "?";
   snprintf(prompt, size - 1, "%s%s[%s] %c ",
           ((shell_env->taskname) ? shell_env->taskname : ""),
           ((shell_env->taskname) ? " " : ""),
-          curdir,
+          cwd,
           geteuid()?'$':'#');
 }




More information about the vc mailing list