fix confparser leaks reported by scan-build, add scan script

This commit is contained in:
2019-01-09 22:44:55 +02:00
parent 1c7b7335e6
commit 579f56df35
5 changed files with 26 additions and 5 deletions

2
.gitignore vendored
View File

@@ -1,6 +1,8 @@
tmp/* tmp/*
*.o *.o
*.bak *.bak
.project
runme.sh
rmpsd rmpsd
agent/*.o agent/*.o
agent/agent agent/agent

12
analyze-clean.sh Executable file
View File

@@ -0,0 +1,12 @@
#!/bin/bash
report_dir=scan-build-$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 6 | head -n 1)
if make clean ; then
scan-build -o "$report_dir" make -j CC=clang
if ls "$report_dir" ; then
scan-view "$report_dir"/*
rm -rf "$report_dir"
fi
fi

View File

@@ -1,2 +0,0 @@
#!/bin/bash
./build/rmpsd start --daemonize=no

View File

@@ -118,7 +118,7 @@ void confexport(void)
conf.rmps.client_poolsize conf.rmps.client_poolsize
); );
} }
/*
static int fopen_and_mkdir(const char *dir) static int fopen_and_mkdir(const char *dir)
{ {
char tmp[256]; char tmp[256];
@@ -154,7 +154,7 @@ static int fopen_and_mkdir(const char *dir)
fclose(fp); fclose(fp);
return 0; return 0;
} }
*/
static int test_conf_perms(char *config) static int test_conf_perms(char *config)
{ {
@@ -167,22 +167,26 @@ static int test_conf_perms(char *config)
if (errno == ENOENT) { if (errno == ENOENT) {
enumtostr(confresult, CONF_MISSING); enumtostr(confresult, CONF_MISSING);
log(ERROR, confresult, config); log(ERROR, confresult, config);
free(config_copy);
return 1; return 1;
} }
} else { } else {
if (!S_ISREG(s.st_mode)) { if (!S_ISREG(s.st_mode)) {
enumtostr(confresult, CONF_NOTFILE); enumtostr(confresult, CONF_NOTFILE);
log(ERROR, confresult, config); log(ERROR, confresult, config);
//free(config_copy);
return 1; return 1;
} }
if (!(0400 & s.st_mode)) { if (!(0400 & s.st_mode)) {
enumtostr(confresult, CONF_PERM); enumtostr(confresult, CONF_PERM);
log(ERROR, confresult, config); log(ERROR, confresult, config);
free(config_copy);
return 1; return 1;
} }
if (access(config, R_OK) != 0) { if (access(config, R_OK) != 0) {
enumtostr(confresult, CONF_NOT_READABLE); enumtostr(confresult, CONF_NOT_READABLE);
log(ERROR, confresult, config); log(ERROR, confresult, config);
free(config_copy);
return 1; return 1;
} }
if (s.st_uid != 0) { if (s.st_uid != 0) {
@@ -204,18 +208,21 @@ static int test_conf_perms(char *config)
if (errno == ENOENT) { if (errno == ENOENT) {
enumtostr(confresult, CONF_DIR_MISSING); enumtostr(confresult, CONF_DIR_MISSING);
log(ERROR, confresult, config_copy); log(ERROR, confresult, config_copy);
free(config_copy);
return 1; return 1;
} }
} else { } else {
if (!S_ISDIR(s.st_mode)) { if (!S_ISDIR(s.st_mode)) {
enumtostr(confresult, CONF_DIR_NOTDIR); enumtostr(confresult, CONF_DIR_NOTDIR);
log(ERROR, confresult, config_copy); log(ERROR, confresult, config_copy);
free(config_copy);
return 1; return 1;
} }
if (!(0400 & s.st_mode) || if (!(0400 & s.st_mode) ||
!(0100 & s.st_mode)) { !(0100 & s.st_mode)) {
enumtostr(confresult, CONF_DIR_PERM); enumtostr(confresult, CONF_DIR_PERM);
log(ERROR, confresult, config_copy); log(ERROR, confresult, config_copy);
free(config_copy);
return 1; return 1;
} }
if (s.st_uid != 0) { if (s.st_uid != 0) {
@@ -230,6 +237,7 @@ static int test_conf_perms(char *config)
log(WARNING, confresult, config_copy); log(WARNING, confresult, config_copy);
} }
} }
free(config_copy);
return 0; /* conf is readable */ return 0; /* conf is readable */
} }

View File

@@ -68,9 +68,10 @@ int add_msg_to_queue(int id, struct msg_t buf)
} }
return -1; return -1;
} }
/*
void create_job(struct msg_t buf) void create_job(struct msg_t buf)
{ {
// add_job_in_db(); // add_job_in_db();
} }
*/