From e795cd8912721e25f2a101723bd17e960db9fa62 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Mon, 23 Dec 2013 13:43:02 +0100 Subject: [PATCH] plugins/python: fix uwsgi_python_harakiri error handling Fixes close with a negative fd. Reported by Coverity as CID #970996. --- plugins/python/python_plugin.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/plugins/python/python_plugin.c b/plugins/python/python_plugin.c index 09ce8f1b..c0c0dffa 100644 --- a/plugins/python/python_plugin.c +++ b/plugins/python/python_plugin.c @@ -1798,19 +1798,22 @@ static void uwsgi_python_harakiri(int wid) { char *address = uwsgi_concat2(up.tracebacker, uwsgi_num2str(wid)); int fd = uwsgi_connect(address, -1, 0); - while (fd >= 0) { - int ret = uwsgi_waitfd(fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]); - if (ret <= 0) { - break; - } - ssize_t len = read(fd, buf, 8192); - if (len <= 0) { - break; - } - uwsgi_log("%.*s", (int) len, buf); - } + if (fd < 1) + goto exit; + int ret = uwsgi_waitfd(fd, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]); + if (ret <= 0) { + goto cleanup; + } + ssize_t len = read(fd, buf, 8192); + if (len <= 0) { + goto cleanup; + } + uwsgi_log("%.*s", (int) len, buf); + +cleanup: close(fd); +exit: free(address); }