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

@ -184,7 +184,8 @@ char c;
} }
cmd = malloc(len); cmd = malloc(len);
strcpy(cmd, argv[optind]); int arglen;
memcpy(cmd, argv[optind], (arglen = strlen(argv[optind])) < 8192 ? arglen : 8192);
for (i = optind +1; i < argc; i++) { for (i = optind +1; i < argc; i++) {
strcat(cmd, " "); strcat(cmd, " ");
strcat(cmd, argv[i]); strcat(cmd, argv[i]);
@ -317,6 +318,7 @@ int keepalive = 1;
{ {
fprintf(stderr, "Unable to connect to MaxScale at %s, %s: %s\n", fprintf(stderr, "Unable to connect to MaxScale at %s, %s: %s\n",
hostname, port, strerror(errno)); hostname, port, strerror(errno));
close(so);
return -1; return -1;
} }
if (setsockopt(so, SOL_SOCKET, if (setsockopt(so, SOL_SOCKET,

View File

@ -78,7 +78,12 @@ int main(int argc, char** argv)
for(i = 0;i<iterations;i++){ for(i = 0;i<iterations;i++){
sprintf(message,"message|%ld",msg_index++); sprintf(message,"message|%ld",msg_index++);
memset(message + strlen(message),' ',block_size - strlen(message)); int msgsize = block_size - strlen(message);
if(msgsize < 0 || msgsize > 8192){
fprintf(stderr,"Error: Message too long");
break;
}
memset(message + strlen(message), ' ', msgsize);
memset(message + block_size - 1,'\0',1); memset(message + block_size - 1,'\0',1);
if(interval > 0 && i % interval == 0){ if(interval > 0 && i % interval == 0){
err = skygw_log_write_flush(LOGFILE_ERROR, message); err = skygw_log_write_flush(LOGFILE_ERROR, message);
@ -90,7 +95,6 @@ int main(int argc, char** argv)
break; break;
} }
usleep(100); usleep(100);
//printf("%s\n",message);
} }
skygw_log_flush(LOGFILE_ERROR); skygw_log_flush(LOGFILE_ERROR);

View File

@ -62,7 +62,7 @@ int main(int argc, char** argv)
*(qbuff->sbuf->data + 1) = (unsigned char)(psize>>8); *(qbuff->sbuf->data + 1) = (unsigned char)(psize>>8);
*(qbuff->sbuf->data + 2) = (unsigned char)(psize>>16); *(qbuff->sbuf->data + 2) = (unsigned char)(psize>>16);
*(qbuff->sbuf->data + 4) = 0x03; *(qbuff->sbuf->data + 4) = 0x03;
strcpy((char*)(qbuff->start + 5),readbuff); memcpy(qbuff->start + 5,readbuff,psize + 1);
parse_query(qbuff); parse_query(qbuff);
tok = skygw_get_canonical(qbuff); tok = skygw_get_canonical(qbuff);
fprintf(outfile,"%s\n",tok); fprintf(outfile,"%s\n",tok);

View File

@ -45,8 +45,8 @@ int main(int argc, char** argv)
input = fopen(argv[1],"rb"); input = fopen(argv[1],"rb");
expected = fopen(argv[2],"rb"); expected = fopen(argv[2],"rb");
memset(buffer,0,buffsz);
while((rd = fread(buffer,sizeof(char),buffsz,input))){ while((rd = fread(buffer,sizeof(char),buffsz - 1,input))){
/**Fill the read buffer*/ /**Fill the read buffer*/
if(strsz + rd >= buffsz){ if(strsz + rd >= buffsz){
@ -167,7 +167,7 @@ int main(int argc, char** argv)
gwbuf_free(buff); gwbuf_free(buff);
} }
memset(buffer,0,buffsz);
} }
fclose(input); fclose(input);
fclose(expected); fclose(expected);

View File

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

View File

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

View File

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

View File

@ -1521,7 +1521,12 @@ int main(int argc, char **argv)
* machine. * machine.
*/ */
sprintf(datadir, "%s/data%d", home_dir, getpid()); 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) if (!daemon_mode)
{ {