Fix overrun in query.c -- calloc too small

This commit is contained in:
Ron Pedde 2004-11-11 19:17:02 +00:00
parent 672d262c17
commit e2bf750033
2 changed files with 13 additions and 12 deletions

View File

@ -80,8 +80,7 @@ CONFIG config;
/* /*
* Forwards * Forwards
*/ */
RETSIGTYPE sig_child(int signal); int daemon_start(void);
int daemon_start(int reap_children);
void write_pid_file(void); void write_pid_file(void);
/* /*
@ -411,8 +410,7 @@ RETSIGTYPE sig_child(int signal)
* This is pretty much stolen straight from Stevens * This is pretty much stolen straight from Stevens
*/ */
int daemon_start(int reap_children) int daemon_start(void) {
{
int childpid, fd; int childpid, fd;
signal(SIGTTOU, SIG_IGN); signal(SIGTTOU, SIG_IGN);
@ -457,9 +455,6 @@ int daemon_start(int reap_children)
chdir("/"); chdir("/");
umask(0); umask(0);
if (reap_children) {
signal(SIGCLD, sig_child);
}
return 0; return 0;
} }
@ -526,6 +521,7 @@ int drop_privs(char *user) {
void *signal_handler(void *arg) { void *signal_handler(void *arg) {
sigset_t intmask; sigset_t intmask;
int sig; int sig;
int status;
config.stop=0; config.stop=0;
config.reload=0; config.reload=0;
@ -534,6 +530,7 @@ void *signal_handler(void *arg) {
while(!config.stop) { while(!config.stop) {
if((sigemptyset(&intmask) == -1) || if((sigemptyset(&intmask) == -1) ||
(sigaddset(&intmask, SIGCLD) == -1) ||
(sigaddset(&intmask, SIGINT) == -1) || (sigaddset(&intmask, SIGINT) == -1) ||
(sigaddset(&intmask, SIGHUP) == -1) || (sigaddset(&intmask, SIGHUP) == -1) ||
(sigwait(&intmask, &sig) == -1)) { (sigwait(&intmask, &sig) == -1)) {
@ -541,6 +538,11 @@ void *signal_handler(void *arg) {
} else { } else {
/* process the signal */ /* process the signal */
switch(sig) { switch(sig) {
case SIGCLD:
DPRINTF(ERR_LOG,"Got CLD signal. Reaping\n");
while (wait(&status)) {
};
break;
case SIGINT: case SIGINT:
DPRINTF(ERR_LOG,"Got INT signal. Notifying daap server.\n"); DPRINTF(ERR_LOG,"Got INT signal. Notifying daap server.\n");
config.stop=1; config.stop=1;
@ -598,7 +600,7 @@ int main(int argc, char *argv[]) {
int reload=0; int reload=0;
int start_time; int start_time;
int end_time; int end_time;
int rescan_counter; int rescan_counter=0;
int old_song_count; int old_song_count;
config.use_mdns=1; config.use_mdns=1;
@ -670,9 +672,8 @@ int main(int argc, char *argv[]) {
drawback that there's a bit less error checking done while drawback that there's a bit less error checking done while
we're attached, but if is much better when being automatically we're attached, but if is much better when being automatically
started as a system service. */ started as a system service. */
if(!foreground) if(!foreground) {
{ daemon_start();
daemon_start(1);
write_pid_file(); write_pid_file();
} }

View File

@ -274,7 +274,7 @@ static query_node_t* match_number(const query_field_t* field,
const char** pcursor, const char** pcursor,
const char* query) const char* query)
{ {
query_node_t* node = (query_node_t*) calloc(1, sizeof(node)); query_node_t* node = (query_node_t*) calloc(1, sizeof(*node));
switch(opcode) switch(opcode)
{ {