mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
out of memory checks: add missing sh_getcwd() wrapper (re: 7ad274f8
)
getcwd() with 0/NULL arguments also mallocs, so needs a check.
This commit is contained in:
parent
f6a6d236f1
commit
a3f4b5efd1
3 changed files with 10 additions and 1 deletions
|
@ -400,6 +400,7 @@ extern void *sh_realloc(void *ptr, size_t size);
|
||||||
extern void *sh_calloc(size_t nmemb, size_t size);
|
extern void *sh_calloc(size_t nmemb, size_t size);
|
||||||
extern char *sh_strdup(const char *s);
|
extern char *sh_strdup(const char *s);
|
||||||
extern void *sh_memdup(const void *s, size_t n);
|
extern void *sh_memdup(const void *s, size_t n);
|
||||||
|
extern char *sh_getcwd(void);
|
||||||
#define new_of(type,x) ((type*)sh_malloc((unsigned)sizeof(type)+(x)))
|
#define new_of(type,x) ((type*)sh_malloc((unsigned)sizeof(type)+(x)))
|
||||||
#define sh_newof(p,t,n,x) ((p)?(t*)sh_realloc((char*)(p),sizeof(t)*(n)+(x)):(t*)sh_calloc(1,sizeof(t)*(n)+(x)))
|
#define sh_newof(p,t,n,x) ((p)?(t*)sh_realloc((char*)(p),sizeof(t)*(n)+(x)):(t*)sh_calloc(1,sizeof(t)*(n)+(x)))
|
||||||
|
|
||||||
|
|
|
@ -271,6 +271,14 @@ void *sh_memdup(const void *s, size_t n)
|
||||||
return(dup);
|
return(dup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *sh_getcwd(void)
|
||||||
|
{
|
||||||
|
char *cwd = getcwd(NIL(char*), 0);
|
||||||
|
if(!cwd && errno==ENOMEM)
|
||||||
|
nomemory(0);
|
||||||
|
return(cwd);
|
||||||
|
}
|
||||||
|
|
||||||
#if SHOPT_VSH || SHOPT_ESH
|
#if SHOPT_VSH || SHOPT_ESH
|
||||||
/* Trap for VISUAL and EDITOR variables */
|
/* Trap for VISUAL and EDITOR variables */
|
||||||
static void put_ed(register Namval_t* np,const char *val,int flags,Namfun_t *fp)
|
static void put_ed(register Namval_t* np,const char *val,int flags,Namfun_t *fp)
|
||||||
|
|
|
@ -262,7 +262,7 @@ char *path_pwd(Shell_t *shp,int flag)
|
||||||
if(!(cp && *cp=='/' && test_inode(cp,e_dot)))
|
if(!(cp && *cp=='/' && test_inode(cp,e_dot)))
|
||||||
{
|
{
|
||||||
/* Get physical PWD (no symlinks) using getcwd(3), fall back to "." */
|
/* Get physical PWD (no symlinks) using getcwd(3), fall back to "." */
|
||||||
cp = getcwd(NIL(char*),0);
|
cp = sh_getcwd();
|
||||||
if(!cp)
|
if(!cp)
|
||||||
return((char*)e_dot);
|
return((char*)e_dot);
|
||||||
tofree++;
|
tofree++;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue