Fixes to some Coverity issues.

This commit is contained in:
Markus Makela
2014-11-05 11:57:42 +02:00
parent 3395caf208
commit 17f87e29af
8 changed files with 52 additions and 17 deletions

View File

@ -116,10 +116,12 @@ char fname[1024], *home;
char uname[80], passwd[80];
initialise();
if ((home = getenv("MAXSCALE_HOME")) != NULL)
if ((home = getenv("MAXSCALE_HOME")) != NULL && strlen(home) < 1024){
sprintf(fname, "%s/etc/passwd", home);
else
}
else{
sprintf(fname, "/usr/local/skysql/MaxScale/etc/passwd");
}
if ((fp = fopen(fname, "r")) == NULL)
return NULL;
if ((rval = users_alloc()) == NULL)
@ -150,10 +152,12 @@ FILE *fp;
char fname[1024], *home, *cpasswd;
initialise();
if ((home = getenv("MAXSCALE_HOME")) != NULL)
if ((home = getenv("MAXSCALE_HOME")) != NULL && strlen(home) < 1024){
sprintf(fname, "%s/etc/passwd", home);
else
}
else{
sprintf(fname, "/usr/local/skysql/MaxScale/etc/passwd");
}
if (users == NULL)
{
@ -246,7 +250,7 @@ char* admin_remove_user(
/**
* Open passwd file and remove user from the file.
*/
if ((home = getenv("MAXSCALE_HOME")) != NULL) {
if ((home = getenv("MAXSCALE_HOME")) != NULL && strlen(home) < 1024) {
sprintf(fname, "%s/etc/passwd", home);
sprintf(fname_tmp, "%s/etc/passwd_tmp", home);
} else {
@ -310,7 +314,12 @@ char* admin_remove_user(
* Unmatching lines are copied to tmp file.
*/
if (strncmp(uname, fusr, strlen(uname)+1) != 0) {
fsetpos(fp, &rpos); /** one step back */
if(fsetpos(fp, &rpos) != 0){ /** one step back */
LOGIF(LE, (skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Unable to set stream position. ")));
}
fgets(line, LINELEN, fp);
fputs(line, fp_tmp);
}