diff options
author | antirez <antirez> | 2005-04-11 08:25:35 +0000 |
---|---|---|
committer | antirez <antirez> | 2005-04-11 08:25:35 +0000 |
commit | be193aab5e275ba30b374ea4622ce3f7cda4422f (patch) | |
tree | 0d2415d760ebd152f860c790facf17926669ca0a /jimsh.c | |
parent | a50382c0e7c7c5516ba2449fa3322ad3e6c775a9 (diff) | |
download | jimtcl-be193aab5e275ba30b374ea4622ce3f7cda4422f.zip jimtcl-be193aab5e275ba30b374ea4622ce3f7cda4422f.tar.gz jimtcl-be193aab5e275ba30b374ea4622ce3f7cda4422f.tar.bz2 |
Fixes for this two bugs:
(1) jim.c Jim_FormatString()
char array spec[] is defined as having two elements but at the
'default:' case of the switch statement an assignment is made to the
third element
(2) jimsh.c JimGetExePath()
After the call of strrchr() the value of p could be NULL in the
case that argv[0] is just plain "jim". The next line should have a test
for NULL added to avoid dereferencing the NULL pointer. (This is the
cause of a Bus Error on Mac OS X.)
Many thanks to Colin McPhail for reporting this two problems.
Diffstat (limited to 'jimsh.c')
-rw-r--r-- | jimsh.c | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -1,7 +1,7 @@ /* Jimsh - An interactive shell for Jim * Copyright 2005 Salvatore Sanfilippo <antirez@invece.org> * - * $Id: jimsh.c,v 1.8 2005/04/10 17:04:13 chi Exp $ + * $Id: jimsh.c,v 1.9 2005/04/11 08:25:36 antirez Exp $ * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -57,11 +57,11 @@ static Jim_Obj *JimGetExePath(Jim_Interp *interp, const char *argv0) /* Check if the executable was called with an absolute pathname */ if (argv0[0] == '/') { - char *p; + char *p; + strncpy(path, argv0, JIM_PATH_LEN); p = strrchr(path, '/'); - if (p != path) - *p = '\0'; + *(p+1) = '\0'; return Jim_NewStringObj(interp, path, -1); } else { char cwd[JIM_PATH_LEN+1]; @@ -76,7 +76,9 @@ static Jim_Obj *JimGetExePath(Jim_Interp *interp, const char *argv0) if (l > 0 && cwd[l-1] == '/') cwd[l-1] = '\0'; p = strrchr(base, '/'); - if (p != base) + if (p == NULL) + base[0] = '\0'; + else if (p != base) *p = '\0'; sprintf(path, "%s/%s", cwd, base); l = strlen(path); |