1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-15 04:32:24 +00:00

dthelp/Initialize.c: coverity CID 89569; unbounded src buf

This commit is contained in:
Jon Trulson 2018-04-01 14:16:18 -06:00
parent 0843325a43
commit cd70f1660d

View file

@ -34,15 +34,17 @@ $COPYRIGHT$:
(c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of Novell, Inc. (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of Novell, Inc.
==$END$==============================================================*/ ==$END$==============================================================*/
#endif /*DOC*/ #endif /*DOC*/
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h>
#include <pwd.h> #include <pwd.h>
#include <ctype.h> #include <ctype.h>
#include <unistd.h> #include <unistd.h>
#include <sys/param.h> /* MAXPATHLEN */ #include <sys/param.h> /* MAXPATHLEN */
#include <sys/stat.h> /* mkdir */ #include <sys/stat.h> /* mkdir */
#include <sys/types.h>
#include <X11/Xlibint.h> /* _XGetHostname() */ #include <X11/Xlibint.h> /* _XGetHostname() */
@ -623,29 +625,30 @@ static char *GetHomeDir (
char *dest) char *dest)
{ /*$CODE$*/ { /*$CODE$*/
uid_t uid; uid_t uid;
extern char *getenv();
extern uid_t getuid();
extern struct passwd *getpwuid(), *getpwnam();
struct passwd *pw; struct passwd *pw;
register char *ptr; char *ptr;
if((ptr = getenv("HOME")) != NULL) if((ptr = getenv("HOME")) != NULL)
{ {
(void) strcpy(dest, ptr); snprintf(dest, MAXPATHLEN, "%s", ptr);
} }
else else
{ {
if((ptr = getenv("USER")) != NULL) if((ptr = getenv("USER")) != NULL)
{ {
pw = getpwnam(ptr); char user[MAXPATHLEN];
} snprintf(user, MAXPATHLEN, "%s", ptr);
else pw = getpwnam(user);
{ }
uid = getuid(); else
pw = getpwuid(uid); {
} uid = getuid();
if (pw) (void) strcpy(dest, pw->pw_dir); pw = getpwuid(uid);
else *dest = '\0'; }
if (pw)
snprintf(dest, MAXPATHLEN, "%s", pw->pw_dir);
else
*dest = '\0';
} }
return dest; return dest;
} /*$END$*/ } /*$END$*/