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);
}

View File

@ -517,8 +517,10 @@ void* gwbuf_get_buffer_object_data(
}
/** Unlock */
spinlock_release(&buf->gwbuf_lock);
return bo->bo_data;
if(bo){
return bo->bo_data;
}
return NULL;
}
/**

View File

@ -461,6 +461,7 @@ int error_count = 0;
if (!succp)
{
if(param){
LOGIF(LM, (skygw_log_write(
LOGFILE_MESSAGE,
"* Warning : invalid value type "
@ -470,6 +471,12 @@ int error_count = 0;
((SERVICE*)obj->element)->name,
param->name,
param->value)));
}else{
LOGIF(LE, (skygw_log_write(
LOGFILE_ERROR,
"Error : parameter was NULL")));
}
}
}
} /*< if (rw_split) */
@ -1306,6 +1313,7 @@ SERVER *server;
if (!succp)
{
if(param){
LOGIF(LM, (skygw_log_write(
LOGFILE_MESSAGE,
"* Warning : invalid value type "
@ -1315,6 +1323,11 @@ SERVER *server;
((SERVICE*)obj->element)->name,
param->name,
param->value)));
}else{
LOGIF(LE, (skygw_log_write(
LOGFILE_ERROR,
"Error : parameter was NULL")));
}
}
}
}
@ -1346,7 +1359,7 @@ SERVER *server;
serviceSetUser(obj->element,
user,
auth);
if (enable_root_user)
if (enable_root_user && service)
serviceEnableRootUser(service, atoi(enable_root_user));
if (allow_localhost_match_wildcard_host)

View File

@ -1521,7 +1521,12 @@ int main(int argc, char **argv)
* machine.
*/
sprintf(datadir, "%s/data%d", home_dir, getpid());
mkdir(datadir, 0777);
if(mkdir(datadir, 0777) != 0){
LOGIF(LE,(skygw_log_write_flush(
LOGFILE_ERROR,
"Error : Directory creation failed due to %s.",
strerror(errno))));
}
if (!daemon_mode)
{