qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acon...@apache.org
Subject svn commit: r1664495 - in /qpid/dispatch/trunk/src: log.c router_agent.c router_node.c
Date Thu, 05 Mar 2015 22:00:00 GMT
Author: aconway
Date: Thu Mar  5 21:59:59 2015
New Revision: 1664495

URL: http://svn.apache.org/r1664495
Log:
NO-JIRA: Fix bugs shown up by coverity scan

Scan: https://scan.coverity.com/projects/3952?tab=overview

log.c
11366 Resource leak
11378 Copy into fixed size buffer

server.c
11351 Logically dead code

router_agent.c
11379 Copy into fixed size buffer

router_node.c
11380 Copy into fixed size buffer

Modified:
    qpid/dispatch/trunk/src/log.c
    qpid/dispatch/trunk/src/router_agent.c
    qpid/dispatch/trunk/src/router_node.c

Modified: qpid/dispatch/trunk/src/log.c
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/src/log.c?rev=1664495&r1=1664494&r2=1664495&view=diff
==============================================================================
--- qpid/dispatch/trunk/src/log.c (original)
+++ qpid/dispatch/trunk/src/log.c Thu Mar  5 21:59:59 2015
@@ -359,11 +359,14 @@ void qd_log_initialize(void)
     DEQ_INIT(entries);
     DEQ_INIT(source_list);
     DEQ_INIT(sink_list);
-    strcpy((char*)level_names, levels[NONE].name);
-    for (level_index_t i = NONE+1; i < N_LEVELS; ++i) {
-        strcat((char*)level_names, ", ");
-        strcat((char*)level_names, levels[i].name);
-    }
+
+    // Set up level_names for use in error messages.
+    ZERO((char*)level_names);
+    char *begin = (char*)level_names, *end = (char*)level_names+sizeof(level_names);
+    aprintf(&begin, end, "%s", levels[NONE].name);
+    for (level_index_t i = NONE + 1; i < N_LEVELS; ++i)
+        aprintf(&begin, end, ", %s", levels[i].name);
+
     log_lock = sys_mutex();
     log_source_lock = sys_mutex();
 
@@ -390,11 +393,10 @@ qd_error_t qd_log_entity(qd_entity_t *en
     qd_error_clear();
     char* module = qd_entity_get_string(entity, "module"); QD_ERROR_RET();
     sys_mutex_lock(log_source_lock);
-    qd_log_source_t *src = qd_log_source_lh(module);
-    assert(src);
-    qd_log_source_t copy = *src;
-    sys_mutex_unlock(log_source_lock);
+    qd_log_source_t *src = qd_log_source_lh(module); /* The original log source */
     free(module);
+    qd_log_source_t copy = *src; /* A copy to modify outside the lock. */
+    sys_mutex_unlock(log_source_lock);
 
     if (qd_entity_has(entity, "enable")) {
         char *enable = qd_entity_get_string(entity, "enable");

Modified: qpid/dispatch/trunk/src/router_agent.c
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/src/router_agent.c?rev=1664495&r1=1664494&r2=1664495&view=diff
==============================================================================
--- qpid/dispatch/trunk/src/router_agent.c (original)
+++ qpid/dispatch/trunk/src/router_agent.c Thu Mar  5 21:59:59 2015
@@ -109,12 +109,9 @@ void qd_router_build_node_list(qd_dispat
     sys_mutex_lock(router->lock);
     qd_router_node_t *rnode = DEQ_HEAD(router->routers);
     while (rnode) {
-        strcpy(temp, "amqp:/_topo/");
-        strcat(temp, router->router_area);
-        strcat(temp, "/");
         const unsigned char* addr = qd_hash_key_by_handle(rnode->owning_addr->hash_handle);
-        strcat(temp, &((char*) addr)[1]);
-        strcat(temp, "/$management");
+        snprintf(temp, sizeof(temp), "amqp:/_topo/%s/%s/$management",
+                router->router_area, &((char*) addr)[1]);
         qd_compose_insert_string(field, temp);
         rnode = DEQ_NEXT(rnode);
     }

Modified: qpid/dispatch/trunk/src/router_node.c
URL: http://svn.apache.org/viewvc/qpid/dispatch/trunk/src/router_node.c?rev=1664495&r1=1664494&r2=1664495&view=diff
==============================================================================
--- qpid/dispatch/trunk/src/router_node.c (original)
+++ qpid/dispatch/trunk/src/router_node.c Thu Mar  5 21:59:59 2015
@@ -2007,8 +2007,7 @@ qd_address_t *qd_router_register_address
     qd_address_t        *addr = 0;
     qd_field_iterator_t *iter = 0;
 
-    strcpy(addr_string, global ? "M0" : "L");
-    strcat(addr_string, address);
+    snprintf(addr_string, sizeof(addr_string), "%s%s", global ? "M0" : "L", address);
     iter = qd_field_iterator_string(addr_string, ITER_VIEW_NO_HOST);
 
     sys_mutex_lock(router->lock);



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message