From 3cdf17df75e2c2eba7c9c829d3f8bde96f4e3467 Mon Sep 17 00:00:00 2001 From: "roberto@silente" Date: Fri, 30 Apr 2010 09:54:25 +0200 Subject: [PATCH] strlcopy insted of strcpy --- snmp.c | 2 +- socket.c | 2 +- utils.c | 2 ++ uwsgi.c | 11 ++++++----- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/snmp.c b/snmp.c index b3d532cf..e13e3e66 100644 --- a/snmp.c +++ b/snmp.c @@ -414,7 +414,7 @@ PyObject *py_snmp_community(PyObject * self, PyObject * args) { memcpy(uwsgi.shared->snmp_community, snmp_community, 72); } else { - strcpy(uwsgi.shared->snmp_community, snmp_community); + strlcpy(uwsgi.shared->snmp_community, snmp_community, 73); } Py_INCREF(Py_True); diff --git a/socket.c b/socket.c index 5dcf55ef..7a267ba7 100644 --- a/socket.c +++ b/socket.c @@ -38,7 +38,7 @@ int bind_to_unix(char *socket_name, int listen_queue, int chmod_socket, int abst } uws_addr->sun_family = AF_UNIX; - strcpy(uws_addr->sun_path + abstract_socket, socket_name); + strlcpy(uws_addr->sun_path + abstract_socket, socket_name, 102+1); if (bind(serverfd, (struct sockaddr *) uws_addr, strlen(socket_name) + abstract_socket + ((void *) uws_addr->sun_path - (void *) uws_addr)) != 0) { uwsgi_error("bind()"); diff --git a/utils.c b/utils.c index 6fb308e4..e92f90da 100644 --- a/utils.c +++ b/utils.c @@ -133,6 +133,8 @@ void daemonize(char *logfile) { exit(1); } + // avoid log mess + setlinebuf(stderr); close(fd); diff --git a/uwsgi.c b/uwsgi.c index fc7b9b54..7654495f 100644 --- a/uwsgi.c +++ b/uwsgi.c @@ -493,7 +493,7 @@ int main(int argc, char *argv[], char *envp[]) { uwsgi_error("malloc()"); exit(1); } - strcpy(uwsgi.binary_path, argv[0]); + strlcpy(uwsgi.binary_path, argv[0], strlen(argv[0]) + 1); } #ifndef UNBIT @@ -1073,7 +1073,8 @@ int main(int argc, char *argv[], char *envp[]) { signal(SIGUSR1, (void *) &stats); #endif -#ifdef UWSGI_SNMP + uwsgi.wsgi_req->buffer = uwsgi.async_buf[0]; +#ifdef UWSGI_UDP if (uwsgi.udp_socket) { uwsgi_poll.fd = bind_to_udp(uwsgi.udp_socket); if (uwsgi_poll.fd < 0) { @@ -1094,7 +1095,7 @@ int main(int argc, char *argv[], char *envp[]) { memcpy(uwsgi.shared->snmp_community, uwsgi.snmp_community, 72); } else { - strcpy(uwsgi.shared->snmp_community, uwsgi.snmp_community); + strlcpy(uwsgi.shared->snmp_community, uwsgi.snmp_community, 73); } } fprintf(stderr, "filling SNMP table..."); @@ -1233,7 +1234,7 @@ int main(int argc, char *argv[], char *envp[]) { } else if (rlen > 0) { udp_len = sizeof(udp_client); - rlen = recvfrom(uwsgi_poll.fd, &uwsgi.wsgi_req->buffer, uwsgi.buffer_size, 0, (struct sockaddr *) &udp_client, &udp_len); + rlen = recvfrom(uwsgi_poll.fd, uwsgi.wsgi_req->buffer, uwsgi.buffer_size, 0, (struct sockaddr *) &udp_client, &udp_len); if (rlen < 0) { uwsgi_error("recvfrom()"); } @@ -2787,7 +2788,7 @@ void uwsgi_cluster_add_node(char *nodename, int workers) { ucn = &uwsgi.shared->nodes[i]; if (ucn->name[0] == 0) { - strcpy(ucn->name, nodename); + strlcpy(ucn->name, nodename, 101); ucn->workers = workers; ucn->ucn_addr.sin_family = AF_INET; ucn->ucn_addr.sin_port = htons(atoi(tcp_port + 1));