From 135a5a505c48a87cede7bab1cde8e93558e4d5f6 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Sat, 26 Jan 2013 19:06:49 +0100 Subject: [PATCH 1/5] lib/linux_ns.c: fix some possible null pointer dereferences In case we cannot open /self/proc/mounts or it is malformed. Spotted by Coverity, CID #971002, #971003. --- lib/linux_ns.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/linux_ns.c b/lib/linux_ns.c index 149aca88..2aa8cb82 100644 --- a/lib/linux_ns.c +++ b/lib/linux_ns.c @@ -201,10 +201,16 @@ void linux_namespace_jail() { unmounted = 0; procmounts = fopen("/proc/self/mounts", "r"); + if (!procmounts) + break; while (fgets(line, 1024, procmounts) != NULL) { delim0 = strchr(line, ' '); + if (!delim0) + continue; delim0++; delim1 = strchr(delim0, ' '); + if (!delim1) + continue; *delim1 = 0; // and now check for keep-mounts if (uwsgi_is_a_keep_mount(delim0)) continue; From 3138d0b6c3bed859ba0f3f4270c24413a5297c8e Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Sat, 26 Jan 2013 19:14:52 +0100 Subject: [PATCH 2/5] plugins/carbon: add missing call to va_end() Reported by Coverity as CID #971091. --- plugins/carbon/carbon.c | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/carbon/carbon.c b/plugins/carbon/carbon.c index b6bf02be..b5573880 100644 --- a/plugins/carbon/carbon.c +++ b/plugins/carbon/carbon.c @@ -107,6 +107,7 @@ int carbon_write(int *fd, char *fmt,...) { int rlen; rlen = vsnprintf(ptr, 4096, fmt, ap); + va_end(ap); if (rlen < 1) return 0; From 386fac2421eeff1919feb29c6bd0f178202cd249 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Sat, 26 Jan 2013 19:18:15 +0100 Subject: [PATCH 3/5] core: fix copy & paste bug in uwsgi_manage_command_cron It looks like tm_hour is used where tm_mon was intended. Reported by Coverity as CID #970975. --- core/master_utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/master_utils.c b/core/master_utils.c index 3b940a36..5b998ab6 100644 --- a/core/master_utils.c +++ b/core/master_utils.c @@ -724,7 +724,7 @@ void uwsgi_manage_command_cron(time_t now) { } } if (current_cron->month < 0) { - if ((uwsgi_cron_delta->tm_hour % abs(current_cron->month)) == 0) { + if ((uwsgi_cron_delta->tm_mon % abs(current_cron->month)) == 0) { uc_month = uwsgi_cron_delta->tm_mon; } } From cbc06f92d07bb8d5dc9b88790ee4913172d75f62 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Sat, 26 Jan 2013 19:29:46 +0100 Subject: [PATCH 4/5] core: add missing unlock in wsgi_req_accept Reported by Coverity as CID #970989. --- core/utils.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/utils.c b/core/utils.c index 248efab5..b9c779b6 100644 --- a/core/utils.c +++ b/core/utils.c @@ -997,8 +997,10 @@ int wsgi_req_accept(int queue, struct wsgi_request *wsgi_req) { if (timeout > 0) { uwsgi_heartbeat(); // no need to continue if timed-out - if (ret == 0) + if (ret == 0) { + thunder_unlock; return -1; + } } #ifdef UWSGI_THREADING From c6ddaf6b8dc2906ff8d712cf990b50831b3a9f77 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Sat, 26 Jan 2013 19:36:26 +0100 Subject: [PATCH 5/5] core: add missing legion mutex unlock on error path Reported by Coverity as CID #970988. --- core/master_utils.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/core/master_utils.c b/core/master_utils.c index 5b998ab6..ce4a290a 100644 --- a/core/master_utils.c +++ b/core/master_utils.c @@ -1202,6 +1202,7 @@ struct uwsgi_stats *uwsgi_master_generate_stats() { #endif #ifdef UWSGI_SSL + struct uwsgi_legion *legion = NULL; if (uwsgi.legions) { if (uwsgi_stats_comma(us)) @@ -1213,7 +1214,7 @@ struct uwsgi_stats *uwsgi_master_generate_stats() { if (uwsgi_stats_list_open(us)) goto end; - struct uwsgi_legion *legion = uwsgi.legions; + legion = uwsgi.legions; while (legion) { if (uwsgi_stats_object_open(us)) goto end; @@ -1283,30 +1284,30 @@ struct uwsgi_stats *uwsgi_master_generate_stats() { struct uwsgi_legion_node *node = legion->nodes_head; while (node) { if (uwsgi_stats_object_open(us)) - goto end; + goto unlock_legion_mutex; if (uwsgi_stats_keyvaln_comma(us, "name", node->name, node->name_len)) - goto end; + goto unlock_legion_mutex; if (uwsgi_stats_keyval_comma(us, "uuid", node->uuid)) - goto end; + goto unlock_legion_mutex; if (uwsgi_stats_keylong_comma(us, "valor", (unsigned long long) node->valor)) - goto end; + goto unlock_legion_mutex; if (uwsgi_stats_keylong_comma(us, "checksum", (unsigned long long) node->checksum)) - goto end; + goto unlock_legion_mutex; if (uwsgi_stats_keylong(us, "last_seen", (unsigned long long) node->last_seen)) - goto end; + goto unlock_legion_mutex; if (uwsgi_stats_object_close(us)) - goto end; + goto unlock_legion_mutex; node = node->next; if (node) { if (uwsgi_stats_comma(us)) - goto end; + goto unlock_legion_mutex; } } pthread_mutex_unlock(&legion->lock); @@ -1335,6 +1336,11 @@ struct uwsgi_stats *uwsgi_master_generate_stats() { goto end; return us; +#ifdef UWSGI_SSL +unlock_legion_mutex: + if (legion) + pthread_mutex_unlock(&legion->lock); +#endif end: free(us->base); free(us);