1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

dtlogin: Coverity (memory corruption, moderate)

This commit is contained in:
Jon Trulson 2014-12-26 16:23:54 -07:00
parent 00540cb375
commit 235a75c03c
5 changed files with 22 additions and 19 deletions

View file

@ -187,7 +187,7 @@ Account( struct display *d, char *user, char *line, pid_t pid,
#else #else
bzero(&utmp, sizeof(struct utmp)); bzero(&utmp, sizeof(struct utmp));
strncpy(utmp.ut_id, d->utmpId, sizeof(u->ut_id)); strncpy(utmp.ut_id, d->utmpId, sizeof(u->ut_id) - 1);
utmp.ut_type = LOGIN_PROCESS; utmp.ut_type = LOGIN_PROCESS;
setutent(); setutent();

View file

@ -273,7 +273,7 @@ RegisterIndirectChoice (
{ {
ChoicePtr c; ChoicePtr c;
int insert; int insert;
int found; int found = 0;
Debug ("Got indirect choice back (%s)\n", Print8Address(clientAddress)); Debug ("Got indirect choice back (%s)\n", Print8Address(clientAddress));
for (c = choices; c; c = c->next) { for (c = choices; c; c = c->next) {

View file

@ -799,7 +799,7 @@ CheckDisplayStatus( struct display *d )
Debug("Check %s: status=%d wakeupTime=%d\n", d->name, Debug("Check %s: status=%d wakeupTime=%d\n", d->name,
d->status, wakeupTime); d->status, wakeupTime);
if (d->status == suspended && wakeupTime >= 0) if (d->status == suspended && wakeupTime >= 0)
if ( GettyRunning(d) || (strcmp(d->gettyLine,"??") == 0)) if ( GettyRunning(d) || (d->gettyLine && (strcmp(d->gettyLine,"??") == 0)) )
if ( wakeupTime == 0 ) { if ( wakeupTime == 0 ) {
Debug("Polling of suspended server %s started.\n", Debug("Polling of suspended server %s started.\n",
d->name); d->name);
@ -1120,7 +1120,7 @@ StartDisplay(
p = DisplayName; p = DisplayName;
strncpy(p, d->name, sizeof(DisplayName)); strncpy(p, d->name, sizeof(DisplayName) - 1);
DisplayName[sizeof(DisplayName)-1] = '\0'; DisplayName[sizeof(DisplayName)-1] = '\0';
if ( (s = strchr(p,':')) != NULL ) if ( (s = strchr(p,':')) != NULL )
@ -1750,11 +1750,15 @@ GettyRunning( struct display *d )
strcpy(utmp.ut_line,ttynm); strcpy(utmp.ut_line,ttynm);
close(fd); close(fd);
} }
else else
strncpy(utmp.ut_line, d->gettyLine, sizeof(utmp.ut_line)); {
strncpy(utmp.ut_line, d->gettyLine, sizeof(utmp.ut_line) - 1);
utmp.ut_line[sizeof(utmp.ut_line) - 1] = 0;
}
#else #else
strncpy(utmp.ut_line, d->gettyLine, sizeof(utmp.ut_line)); strncpy(utmp.ut_line, d->gettyLine, sizeof(utmp.ut_line) - 1);
utmp.ut_line[sizeof(utmp.ut_line) - 1] = 0;
#endif #endif
Debug("Checking for a getty on line %s.\n", utmp.ut_line); Debug("Checking for a getty on line %s.\n", utmp.ut_line);

View file

@ -236,7 +236,8 @@ TrimErrorFile( void )
return; return;
} }
n = read(f2, buf, BUFSIZ); memset(buf, 0, BUFSIZ);
n = read(f2, buf, BUFSIZ - 1);
if ( (p = strchr(buf,'\n')) != NULL ) { if ( (p = strchr(buf,'\n')) != NULL ) {
p++; p++;

View file

@ -186,7 +186,7 @@ ParseDisplay( char *source,
struct passwd *puser) struct passwd *puser)
{ {
char **args, **argv, **a; char **args, **argv, **a;
char *name, *class, *type; char *name = NULL, *class, *type;
struct display *d; struct display *d;
int usedDefaultType; int usedDefaultType;
int parse_uid; int parse_uid;
@ -204,7 +204,7 @@ ParseDisplay( char *source,
freeArgs (args); freeArgs (args);
return 0; return 0;
} }
name = args[0]; name = strdup(args[0]);
if (!args[1]) if (!args[1])
{ {
LogError(ReadCatalog(MC_LOG_SET,MC_LOG_MISS_TYPE,MC_DEF_LOG_MISS_TYPE), LogError(ReadCatalog(MC_LOG_SET,MC_LOG_MISS_TYPE,MC_DEF_LOG_MISS_TYPE),
@ -236,22 +236,19 @@ ParseDisplay( char *source,
char tname[128]; char tname[128];
struct hostent *hostent; struct hostent *hostent;
strcpy(tname,""); memset(tname, 0, 128);
gethostname(tname, sizeof(tname)); gethostname(tname, 128 - 1);
if ( (hostent = gethostbyname(tname)) == NULL ) { if ( (hostent = gethostbyname(tname)) == NULL ) {
LogError( LogError(
ReadCatalog(MC_LOG_SET,MC_LOG_INV_HOSTNM,MC_DEF_LOG_INV_HOSTNM), ReadCatalog(MC_LOG_SET,MC_LOG_INV_HOSTNM,MC_DEF_LOG_INV_HOSTNM),
tname); tname);
strcpy(tname,""); tname[0] = 0;
} }
/*
else
strcpy(tname,hostent->h_name);
*/
strcat(tname, ":0"); strncat(tname, ":0", 128 - 1);
name = tname; free(name);
name = strdup(tname);
} }
/* /*
@ -372,6 +369,7 @@ ParseDisplay( char *source,
freeSomeArgs (args, argv - args); freeSomeArgs (args, argv - args);
free(name);
return 1; return 1;
} }