You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by rj...@apache.org on 2022/07/04 16:35:49 UTC

[tomcat-connectors] branch main updated: Common: Fix compiler warning when nitializing and copying fixed length strings.

This is an automated email from the ASF dual-hosted git repository.

rjung pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat-connectors.git


The following commit(s) were added to refs/heads/main by this push:
     new 97bc5677a Common: Fix compiler warning when nitializing and copying fixed length strings.
97bc5677a is described below

commit 97bc5677af22184bb7fe56d5e41fc76617b5cdbf
Author: Rainer Jung <ra...@kippdata.de>
AuthorDate: Mon Jul 4 18:35:25 2022 +0200

    Common: Fix compiler warning when nitializing and copying fixed length strings.
---
 native/common/jk_ajp_common.c     | 21 ++++++++--------
 native/common/jk_ajp_common.h     |  6 ++---
 native/common/jk_lb_worker.c      | 41 ++++++++++++++----------------
 native/common/jk_lb_worker.h      | 16 ++++++------
 native/common/jk_shm.c            | 52 ++++++++++++++++++++++++++++++++++++---
 native/common/jk_shm.h            | 21 ++++++++++++----
 native/common/jk_status.c         | 48 ++++++++++++++++++------------------
 native/common/jk_uri_worker_map.c |  2 +-
 native/common/jk_util.c           | 38 +++++++++-------------------
 native/common/jk_util.h           |  3 ---
 native/common/jk_worker.c         |  4 ---
 xdocs/miscellaneous/changelog.xml |  4 +++
 12 files changed, 146 insertions(+), 110 deletions(-)

diff --git a/native/common/jk_ajp_common.c b/native/common/jk_ajp_common.c
index 02c090bc5..5e078c608 100644
--- a/native/common/jk_ajp_common.c
+++ b/native/common/jk_ajp_common.c
@@ -1122,7 +1122,7 @@ void jk_ajp_pull(ajp_worker_t * aw, int locked, jk_log_context_t *l)
 {
     int address_change = JK_FALSE;
     int port = 0;
-    char host[JK_SHM_STR_SIZ];
+    shm_str host;
     jk_sockaddr_t inet_addr;
     JK_TRACE_ENTER(l);
 
@@ -1148,7 +1148,7 @@ void jk_ajp_pull(ajp_worker_t * aw, int locked, jk_log_context_t *l)
     if (aw->addr_sequence != aw->s->addr_sequence) {
         address_change = JK_TRUE;
         aw->addr_sequence = aw->s->addr_sequence;
-        strncpy(host, aw->s->host, JK_SHM_STR_SIZ);
+        jk_shm_str_copy(host, aw->s->host, l);
         port = aw->s->port;
     }
     if (locked == JK_FALSE)
@@ -1156,7 +1156,7 @@ void jk_ajp_pull(ajp_worker_t * aw, int locked, jk_log_context_t *l)
 
     if (address_change == JK_TRUE && port != 0) {
         aw->port = port;
-        strncpy(aw->host, host, JK_SHM_STR_SIZ);
+        jk_shm_str_copy(aw->host, host, l);
         if (!jk_resolve(host, port, &inet_addr,
                         aw->worker.we->pool, aw->prefer_ipv6, l)) {
             jk_log(l, JK_LOG_ERROR,
@@ -1222,7 +1222,7 @@ void jk_ajp_push(ajp_worker_t * aw, int locked, jk_log_context_t *l)
     if (aw->s->addr_sequence != aw->addr_sequence) {
         ++aw->s->addr_sequence;
         address_change = JK_TRUE;
-        strncpy(aw->s->host, aw->host, JK_SHM_STR_SIZ);
+        jk_shm_str_copy(aw->s->host, aw->host, l);
         aw->s->port = aw->port;
         aw->addr_sequence = aw->s->addr_sequence;
     }
@@ -2925,18 +2925,16 @@ int ajp_validate(jk_worker_t *pThis,
             host = "undefined";
         }
         tmp = jk_get_worker_host(props, p->name, host);
-        if (jk_check_attribute_length("host name", tmp, l) == JK_FALSE) {
+        if (jk_shm_str_init(p->host, tmp, "host name", l) == JK_FALSE) {
             JK_TRACE_EXIT(l);
             return JK_FALSE;
         }
-        strncpy(p->host, tmp, JK_SHM_STR_SIZ);
         p->prefer_ipv6 = jk_get_worker_prefer_ipv6(props, p->name, JK_FALSE);
         tmp = jk_get_worker_source(props, p->name, "");
-        if (jk_check_attribute_length("source address", tmp, l) == JK_FALSE) {
+        if (jk_shm_str_init(p->source, tmp, "source address", l) == JK_FALSE) {
             JK_TRACE_EXIT(l);
             return JK_FALSE;
         }
-        strncpy(p->source, tmp, JK_SHM_STR_SIZ);
         if (p->s->h.sequence == 0) {
             /* Initial setup.
              */
@@ -2971,7 +2969,7 @@ int ajp_validate(jk_worker_t *pThis,
             p->s->last_maintain_time = time(NULL);
             p->s->last_reset = p->s->last_maintain_time;
             p->s->port = p->port;
-            strncpy(p->s->host, p->host, JK_SHM_STR_SIZ);
+            jk_shm_str_copy(p->s->host, p->host, l);
             jk_ajp_push(p, JK_TRUE, l);
         }
         else {
@@ -3266,7 +3264,10 @@ int JK_METHOD ajp_worker_factory(jk_worker_t **w,
                  aw->buf,
                  sizeof(jk_pool_atom_t) * TINY_POOL_SIZE);
 
-    strncpy(aw->name, name, JK_SHM_STR_SIZ);
+    if (jk_shm_str_init(aw->name, name, "name", l) == JK_FALSE) {
+        JK_TRACE_EXIT(l);
+        return JK_FALSE;
+    }
     aw->login = NULL;
 
     aw->ep_cache_sz = 0;
diff --git a/native/common/jk_ajp_common.h b/native/common/jk_ajp_common.h
index a2402b2c2..c0827f523 100644
--- a/native/common/jk_ajp_common.h
+++ b/native/common/jk_ajp_common.h
@@ -287,7 +287,7 @@ struct ajp_worker
     /* Shared memory worker data */
     jk_shm_ajp_worker_t *s;
 
-    char         name[JK_SHM_STR_SIZ];
+    shm_str name;
     /* Sequence counter starting at 0 and increasing
      * every time we change the config
      */
@@ -301,9 +301,9 @@ struct ajp_worker
     jk_sockaddr_t worker_inet_addr;    /* Contains host and port */
     jk_sockaddr_t worker_source_inet_addr; /* Contains source ip */
     unsigned connect_retry_attempts;
-    char host[JK_SHM_STR_SIZ];
+    shm_str host;
     int port;
-    char source[JK_SHM_STR_SIZ];
+    shm_str source;
     int addr_sequence;  /* Whether the address is resolved */
     int maintain_time;
     int prefer_ipv6;
diff --git a/native/common/jk_lb_worker.c b/native/common/jk_lb_worker.c
index e9a69156b..133bcd735 100644
--- a/native/common/jk_lb_worker.c
+++ b/native/common/jk_lb_worker.c
@@ -316,9 +316,9 @@ static void jk_lb_pull_worker(lb_worker_t *p, int i, jk_log_context_t *l)
                    w->name, p->name);
 
         jk_ajp_pull(aw, JK_TRUE, l);
-        strncpy(w->route, w->s->route, JK_SHM_STR_SIZ);
-        strncpy(w->domain, w->s->domain, JK_SHM_STR_SIZ);
-        strncpy(w->redirect, w->s->redirect, JK_SHM_STR_SIZ);
+        jk_shm_str_copy(w->route, w->s->route, l);
+        jk_shm_str_copy(w->domain, w->s->domain, l);
+        jk_shm_str_copy(w->redirect, w->s->redirect, l);
         w->distance = w->s->distance;
         w->activation = w->s->activation;
         w->lb_factor = w->s->lb_factor;
@@ -402,9 +402,9 @@ void jk_lb_push(lb_worker_t *p, int locked, int push_all_members, jk_log_context
                        w->name, p->name);
 
             jk_ajp_push(aw, JK_TRUE, l);
-            strncpy(w->s->route, w->route, JK_SHM_STR_SIZ);
-            strncpy(w->s->domain, w->domain, JK_SHM_STR_SIZ);
-            strncpy(w->s->redirect, w->redirect, JK_SHM_STR_SIZ);
+            jk_shm_str_copy(w->s->route, w->route, l);
+            jk_shm_str_copy(w->s->domain, w->domain, l);
+            jk_shm_str_copy(w->s->redirect, w->redirect, l);
             w->s->distance = w->distance;
             w->s->activation = w->activation;
             w->s->lb_factor = w->lb_factor;
@@ -1745,10 +1745,11 @@ static int JK_METHOD validate(jk_worker_t *pThis,
             }
             memset(p->lb_workers, 0, num_of_workers * sizeof(lb_sub_worker_t));
             for (i = 0; i < num_of_workers; i++) {
-                if (jk_check_attribute_length("host name", worker_names[i], l) == JK_FALSE) {
+                if (jk_shm_str_init(p->lb_workers[i].name, worker_names[i], "name", l) == JK_FALSE) {
                     JK_TRACE_EXIT(l);
                     return JK_FALSE;
                 }
+                jk_shm_str_copy(p->lb_workers[i].route, p->lb_workers[i].name, l);
                 p->lb_workers[i].s = jk_shm_alloc_lb_sub_worker(&p->p, p->s->h.id, worker_names[i], l);
                 if (p->lb_workers[i].s == NULL) {
                     jk_log(l, JK_LOG_ERROR,
@@ -1757,7 +1758,6 @@ static int JK_METHOD validate(jk_worker_t *pThis,
                     return JK_FALSE;
                 }
                 p->lb_workers[i].i = i;
-                strncpy(p->lb_workers[i].name, worker_names[i], JK_SHM_STR_SIZ);
             }
 
             for (i = 0; i < num_of_workers; i++) {
@@ -1796,27 +1796,22 @@ static int JK_METHOD validate(jk_worker_t *pThis,
                 p->lb_workers[i].distance =
                     jk_get_distance(props, worker_names[i]);
                 if ((s = jk_get_worker_route(props, worker_names[i], NULL))) {
-                    if (jk_check_attribute_length("route", s, l) == JK_FALSE) {
+                    if (jk_shm_str_init(p->lb_workers[i].route, s, "route", l) == JK_FALSE) {
                         JK_TRACE_EXIT(l);
                         return JK_FALSE;
                     }
-                    strncpy(p->lb_workers[i].route, s, JK_SHM_STR_SIZ);
                 }
-                else
-                    strncpy(p->lb_workers[i].route, worker_names[i], JK_SHM_STR_SIZ);
                 if ((s = jk_get_worker_domain(props, worker_names[i], NULL))) {
-                    if (jk_check_attribute_length("domain", s, l) == JK_FALSE) {
+                    if (jk_shm_str_init(p->lb_workers[i].domain, s, "domain", l) == JK_FALSE) {
                         JK_TRACE_EXIT(l);
                         return JK_FALSE;
                     }
-                    strncpy(p->lb_workers[i].domain, s, JK_SHM_STR_SIZ);
                 }
                 if ((s = jk_get_worker_redirect(props, worker_names[i], NULL))) {
-                    if (jk_check_attribute_length("redirect", s, l) == JK_FALSE) {
+                    if (jk_shm_str_init(p->lb_workers[i].redirect, s, "redirect", l) == JK_FALSE) {
                         JK_TRACE_EXIT(l);
                         return JK_FALSE;
                     }
-                    strncpy(p->lb_workers[i].redirect, s, JK_SHM_STR_SIZ);
                 }
 
                 p->lb_workers[i].s->lb_value = 0;
@@ -1943,24 +1938,21 @@ static int JK_METHOD init(jk_worker_t *pThis,
 #endif
     p->lblock   = jk_get_lb_lock(props, p->name);
     s = jk_get_lb_session_cookie(props, p->name, JK_SESSION_IDENTIFIER);
-    if (jk_check_attribute_length("session_cookie", s, l) == JK_FALSE) {
+    if (jk_shm_str_init(p->session_cookie, s, "session_cookie", l) == JK_FALSE) {
         JK_TRACE_EXIT(l);
         return JK_FALSE;
     }
-    strncpy(p->session_cookie, s, JK_SHM_STR_SIZ);
     s = jk_get_lb_session_path(props, p->name, JK_PATH_SESSION_IDENTIFIER);
-    if (jk_check_attribute_length("session_path", s, l) == JK_FALSE) {
+    if (jk_shm_str_init(p->session_path, s, "session_path", l) == JK_FALSE) {
         JK_TRACE_EXIT(l);
         return JK_FALSE;
     }
-    strncpy(p->session_path, s, JK_SHM_STR_SIZ);
     p->set_session_cookie = jk_get_lb_set_session_cookie(props, p->name, JK_FALSE);
     s = jk_get_lb_session_cookie_path(props, p->name, "/");
-    if (jk_check_attribute_length("session_cookie_path", s, l) == JK_FALSE) {
+    if (jk_shm_str_init(p->session_cookie_path, s, "session_cookie_path", l) == JK_FALSE) {
         JK_TRACE_EXIT(l);
         return JK_FALSE;
     }
-    strncpy(p->session_cookie_path, s, JK_SHM_STR_SIZ);
 
     JK_INIT_CS(&(p->cs), i);
     if (i == JK_FALSE) {
@@ -2057,7 +2049,10 @@ int JK_METHOD lb_worker_factory(jk_worker_t **w,
             JK_TRACE_EXIT(l);
             return 0;
         }
-        strncpy(private_data->name, name, JK_SHM_STR_SIZ);
+        if (jk_shm_str_init(private_data->name, name, "name", l) == JK_FALSE) {
+            JK_TRACE_EXIT(l);
+            return 0;
+        }
         private_data->lb_workers = NULL;
         private_data->num_of_workers = 0;
         private_data->worker.worker_private = private_data;
diff --git a/native/common/jk_lb_worker.h b/native/common/jk_lb_worker.h
index 06ada6244..6d800d5a4 100644
--- a/native/common/jk_lb_worker.h
+++ b/native/common/jk_lb_worker.h
@@ -136,18 +136,18 @@ struct lb_sub_worker
     /* Shared memory worker data */
     jk_shm_lb_sub_worker_t *s;
 
-    char         name[JK_SHM_STR_SIZ];
+    shm_str      name;
     /* Sequence counter starting at 0 and increasing
      * every time we change the config
      */
     volatile unsigned int sequence;
 
     /* route */
-    char    route[JK_SHM_STR_SIZ];
+    shm_str route;
     /* worker domain */
-    char    domain[JK_SHM_STR_SIZ];
+    shm_str domain;
     /* worker redirect route */
-    char    redirect[JK_SHM_STR_SIZ];
+    shm_str redirect;
     /* worker distance */
     int distance;
     /* current activation state (config) of the worker */
@@ -167,7 +167,7 @@ struct lb_worker
     /* Shared memory worker data */
     jk_shm_lb_worker_t *s;
 
-    char         name[JK_SHM_STR_SIZ];
+    shm_str      name;
     /* Sequence counter starting at 0 and increasing
      * every time we change the config
      */
@@ -194,11 +194,11 @@ struct lb_worker
     unsigned int max_packet_size;
     unsigned int next_offset;
     /* Session cookie */
-    char         session_cookie[JK_SHM_STR_SIZ];
+    shm_str      session_cookie;
     /* Session path */
-    char         session_path[JK_SHM_STR_SIZ];
+    shm_str      session_path;
     int          set_session_cookie;
-    char         session_cookie_path[JK_SHM_STR_SIZ];
+    shm_str      session_cookie_path;
 };
 typedef struct lb_worker lb_worker_t;
 
diff --git a/native/common/jk_shm.c b/native/common/jk_shm.c
index 784aa4250..a3c5fb433 100644
--- a/native/common/jk_shm.c
+++ b/native/common/jk_shm.c
@@ -806,14 +806,60 @@ void jk_shm_close(jk_log_context_t *l)
 
 #endif
 
+static int jk_shm_check_str_length(const char *name, const char *value,
+                                   jk_log_context_t *l)
+{
+    size_t len = strlen(value);
+    if (len >= JK_SHM_STR_SIZ) {
+        jk_log(l, JK_LOG_ERROR,
+               "Worker %s '%s' is %d bytes too long, "
+               "a maximum of %d bytes is supported",
+               name, value, len - (JK_SHM_STR_SIZ - 1), JK_SHM_STR_SIZ - 1);
+        return JK_FALSE;
+    }
+    return JK_TRUE;
+}
+
+int jk_shm_str_init(shm_str dst, const char *src,
+                    const char *name, jk_log_context_t *l)
+{
+    if (jk_shm_check_str_length(name, src, l) == JK_FALSE) {
+        return JK_FALSE;
+    }
+    strncpy(dst, src, JK_SHM_STR_SIZ - 1);
+    dst[JK_SHM_STR_SIZ - 1] = '\0';
+    return JK_TRUE;
+}
+
+int jk_shm_str_init_ne(shm_str dst, const char *src,
+                       const char *name, jk_log_context_t *l)
+{
+    if (jk_shm_check_str_length(name, src, l) == JK_FALSE) {
+        return -1;
+    }
+    if (!strncmp(dst, src, JK_SHM_STR_SIZ)) {
+        return 0;
+    }
+    strncpy(dst, src, JK_SHM_STR_SIZ - 1);
+    dst[JK_SHM_STR_SIZ - 1] = '\0';
+    return 1;
+}
+
+void jk_shm_str_copy(shm_str dst, shm_str src,
+                     jk_log_context_t *l)
+{
+    memcpy((dst), (src), JK_SHM_STR_SIZ);
+}
+
 jk_shm_worker_header_t *jk_shm_alloc_worker(jk_pool_t *p, int type,
                                             int parent_id, const char *name,
                                             jk_log_context_t *l)
 {
     unsigned int i;
     jk_shm_worker_header_t *w = 0;
+    shm_str str;
 
-    if (jk_check_attribute_length("name", name, l) == JK_FALSE) {
+    if (jk_shm_str_init(str, name, "name", l) == JK_FALSE) {
         return NULL;
     }
 
@@ -832,7 +878,7 @@ jk_shm_worker_header_t *jk_shm_alloc_worker(jk_pool_t *p, int type,
         if ((jk_shmem.hdr->h.data.size - jk_shmem.hdr->h.data.pos) >= JK_SHM_SLOT_SIZE) {
             w = (jk_shm_worker_header_t *)(jk_shmem.hdr->buf + jk_shmem.hdr->h.data.pos);
             memset(w, 0, JK_SHM_SLOT_SIZE);
-            strncpy(w->name, name, JK_SHM_STR_SIZ);
+            jk_shm_str_copy(w->name, str, l);
             jk_shmem.hdr->h.data.workers++;
             w->id = jk_shmem.hdr->h.data.workers;
             w->type = type;
@@ -853,7 +899,7 @@ jk_shm_worker_header_t *jk_shm_alloc_worker(jk_pool_t *p, int type,
         w = (jk_shm_worker_header_t *)jk_pool_alloc(p, JK_SHM_SLOT_SIZE);
         if (w) {
             memset(w, 0, JK_SHM_SLOT_SIZE);
-            strncpy(w->name, name, JK_SHM_STR_SIZ);
+            jk_shm_str_copy(w->name, str, l);
             w->id = 0;
             w->type = type;
             w->parent_id = parent_id;
diff --git a/native/common/jk_shm.h b/native/common/jk_shm.h
index a07f7cb4e..36996ee47 100644
--- a/native/common/jk_shm.h
+++ b/native/common/jk_shm.h
@@ -54,6 +54,8 @@ extern "C"
 #define JK_SHM_MIN_SIZE           ((JK_SHM_SLOT_SIZE * JK_SHM_DEF_WORKERS * 3) + \
                                    JK_SHM_ALIGNMENT)
 
+typedef char shm_str[JK_SHM_STR_SIZ];
+
 /** jk shm generic worker record structure */
 struct jk_shm_worker_header
 {
@@ -62,7 +64,7 @@ struct jk_shm_worker_header
     /* JK_XXX_WORKER_TYPE */
     int     type;
     /* worker name */
-    char    name[JK_SHM_STR_SIZ];
+    shm_str name;
     /* parent slot id.
      * Zero in case worker does not belong to balancer.
      */
@@ -78,7 +80,7 @@ typedef struct jk_shm_worker_header jk_shm_worker_header_t;
 struct jk_shm_ajp_worker
 {
     jk_shm_worker_header_t h;
-    char host[JK_SHM_STR_SIZ];
+    shm_str host;
     int port;
     volatile int addr_sequence;
 
@@ -131,11 +133,11 @@ struct jk_shm_lb_sub_worker
     jk_shm_worker_header_t h;
 
     /* route */
-    char    route[JK_SHM_STR_SIZ];
+    shm_str route;
     /* worker domain */
-    char    domain[JK_SHM_STR_SIZ];
+    shm_str domain;
     /* worker redirect route */
-    char    redirect[JK_SHM_STR_SIZ];
+    shm_str redirect;
     /* worker distance */
     volatile int distance;
     /* current activation state (config) of the worker */
@@ -186,6 +188,15 @@ struct jk_shm_lb_worker
 };
 typedef struct jk_shm_lb_worker jk_shm_lb_worker_t;
 
+int jk_shm_str_init(shm_str dst, const char *src,
+                    const char *name, jk_log_context_t *l);
+
+int jk_shm_str_init_ne(shm_str dst, const char *src,
+                       const char *name, jk_log_context_t *l);
+
+void jk_shm_str_copy(shm_str dst, shm_str src,
+                     jk_log_context_t *l);
+
 const char *jk_shm_name(void);
 
 /* Calculate needed shm size */
diff --git a/native/common/jk_status.c b/native/common/jk_status.c
index f051d041a..4b7dd66cc 100644
--- a/native/common/jk_status.c
+++ b/native/common/jk_status.c
@@ -3416,7 +3416,7 @@ static int commit_member(jk_ws_service_t *s,
     int i;
     int old;
     int resolve = JK_FALSE;
-    char host[JK_SHM_STR_SIZ];
+    shm_str host;
     int  port = 0;
 
     JK_TRACE_ENTER(l);
@@ -3451,7 +3451,8 @@ static int commit_member(jk_ws_service_t *s,
             *side_effect |= JK_STATUS_NEEDS_UPDATE_MULT | JK_STATUS_NEEDS_PUSH;
         if ((rv = status_get_string(p, JK_STATUS_ARG_LBM_ROUTE,
                                     NULL, &arg, l)) == JK_TRUE) {
-            if (jk_check_attribute_length("route", arg, l) == JK_FALSE) {
+            int ret = jk_shm_str_init_ne(wr->route, arg, "route", l);
+            if (ret == -1) {
                 const char *msg = "Update failed (at least partially): new route '%s' "
                                   "too long for sub worker '%s', see log file for details.";
                 size_t size = strlen(msg) + strlen(arg) + strlen(wr->name) + 1;
@@ -3459,11 +3460,10 @@ static int commit_member(jk_ws_service_t *s,
                 snprintf(p->msg, size, msg, arg, aw->name);
                 rc = JK_FALSE;
             }
-            else if (strncmp(wr->route, arg, JK_SHM_STR_SIZ)) {
+            else if (ret != 0) {
                 jk_log(l, JK_LOG_INFO,
                        "Status worker '%s' changing 'route' for sub worker '%s' of lb worker '%s' from '%s' to '%s'",
                        w->name, wr->name, lb_name, wr->route, arg);
-                strncpy(wr->route, arg, JK_SHM_STR_SIZ);
                 *side_effect |= JK_STATUS_NEEDS_PUSH;
                 if (!wr->domain[0]) {
                     char * id_domain = strchr(wr->route, '.');
@@ -3477,7 +3477,8 @@ static int commit_member(jk_ws_service_t *s,
         }
         if ((rv = status_get_string(p, JK_STATUS_ARG_LBM_REDIRECT,
                                     NULL, &arg, l)) == JK_TRUE) {
-            if (jk_check_attribute_length("redirect", arg, l) == JK_FALSE) {
+            int ret = jk_shm_str_init_ne(wr->redirect, arg, "redirect", l);
+            if (ret == -1) {
                 const char *msg = "Update failed (at least partially): new redirect '%s' "
                                   "too long for sub worker '%s', see log file for details.";
                 size_t size = strlen(msg) + strlen(arg) + strlen(wr->name) + 1;
@@ -3485,17 +3486,17 @@ static int commit_member(jk_ws_service_t *s,
                 snprintf(p->msg, size, msg, arg, aw->name);
                 rc = JK_FALSE;
             }
-            else if (strncmp(wr->redirect, arg, JK_SHM_STR_SIZ)) {
+            else if (ret != 0) {
                 jk_log(l, JK_LOG_INFO,
                        "Status worker '%s' changing 'redirect' for sub worker '%s' of lb worker '%s' from '%s' to '%s'",
                        w->name, wr->name, lb_name, wr->redirect, arg);
-                strncpy(wr->redirect, arg, JK_SHM_STR_SIZ);
                 *side_effect |= JK_STATUS_NEEDS_PUSH;
             }
         }
         if ((rv = status_get_string(p, JK_STATUS_ARG_LBM_DOMAIN,
                                     NULL, &arg, l)) == JK_TRUE) {
-            if (jk_check_attribute_length("domain", arg, l) == JK_FALSE) {
+            int ret = jk_shm_str_init_ne(wr->domain, arg, "domain", l);
+            if (ret == -1) {
                 const char *msg = "Update failed (at least partially): new domain '%s' "
                                   "too long for sub worker '%s', see log file for details.";
                 size_t size = strlen(msg) + strlen(arg) + strlen(wr->name) + 1;
@@ -3503,11 +3504,10 @@ static int commit_member(jk_ws_service_t *s,
                 snprintf(p->msg, size, msg, arg, aw->name);
                 rc = JK_FALSE;
             }
-            else if (strncmp(wr->domain, arg, JK_SHM_STR_SIZ)) {
+            else if (ret != 0) {
                 jk_log(l, JK_LOG_INFO,
                        "Status worker '%s' changing 'domain' for sub worker '%s' of lb worker '%s' from '%s' to '%s'",
                        w->name, wr->name, lb_name, wr->domain, arg);
-                strncpy(wr->domain, arg, JK_SHM_STR_SIZ);
                 *side_effect |= JK_STATUS_NEEDS_PUSH;
             }
         }
@@ -3531,12 +3531,13 @@ static int commit_member(jk_ws_service_t *s,
     port = aw->port;
     if (set_int_if_changed(p, aw->name, "port", JK_STATUS_ARG_AJP_PORT,
                            0, INT_MAX, &port, lb_name, l)) {
-        strncpy(host, aw->host, JK_SHM_STR_SIZ);
+        jk_shm_str_copy(host, aw->host, l);
         resolve = JK_TRUE;
     }
     if ((rv = status_get_string(p, JK_STATUS_ARG_AJP_HOST_STR,
                                 NULL, &arg, l)) == JK_TRUE) {
-        if (jk_check_attribute_length("host name", arg, l) == JK_FALSE) {
+        int ret = jk_shm_str_init_ne(host, arg, "host name", l);
+        if (ret == -1) {
             const char *msg = "Update failed (at least partially): new host name '%s' "
                               "too long for sub worker '%s', see log file for details.";
             size_t size = strlen(msg) + strlen(arg) + strlen(aw->name) + 1;
@@ -3544,11 +3545,10 @@ static int commit_member(jk_ws_service_t *s,
             snprintf(p->msg, size, msg, arg, aw->name);
             rc = JK_FALSE;
         }
-        else if (strncmp(aw->host, arg, JK_SHM_STR_SIZ)) {
+        else if (ret != 0) {
             jk_log(l, JK_LOG_INFO,
                    "Status worker '%s' changing 'host' for sub worker '%s' from '%s' to '%s'",
                    w->name, aw->name, aw->host, arg);
-            strncpy(host, arg, JK_SHM_STR_SIZ);
             resolve = JK_TRUE;
         }
     }
@@ -3568,7 +3568,7 @@ static int commit_member(jk_ws_service_t *s,
         else {
             /* This is not atomic and not thread safe */
             aw->port = port;
-            strncpy(aw->host, host, JK_SHM_STR_SIZ);
+            jk_shm_str_copy(aw->host, host, l);
             jk_clone_sockaddr(&(aw->worker_inet_addr), &inet_addr);
             *side_effect |= JK_STATUS_NEEDS_PUSH | JK_STATUS_NEEDS_ADDR_PUSH;
         }
@@ -3802,7 +3802,8 @@ static void commit_all_members(jk_ws_service_t *s,
                 }
                 else if (!strcmp(attribute, JK_STATUS_ARG_LBM_ROUTE)) {
                     if (rv == JK_TRUE) {
-                        if (jk_check_attribute_length("route", arg, l) == JK_FALSE) {
+                        int ret = jk_shm_str_init_ne(wr->route, arg, "route", l);
+                        if (ret == -1) {
                             const char *msg = "Update failed (at least partially): new route '%s' "
                                               "too long for sub worker '%s', see log file for details.";
                             size_t size = strlen(msg) + strlen(arg) + strlen(wr->name) + 1;
@@ -3810,11 +3811,10 @@ static void commit_all_members(jk_ws_service_t *s,
                             snprintf(p->msg, size, msg, arg, aw->name);
                             rc = JK_FALSE;
                         }
-                        else if (strncmp(wr->route, arg, JK_SHM_STR_SIZ)) {
+                        else if (ret != 0) {
                             jk_log(l, JK_LOG_INFO,
                                    "Status worker '%s' changing 'route' for sub worker '%s' of lb worker '%s' from '%s' to '%s'",
                                    w->name, wr->name, name, wr->route, arg);
-                            strncpy(wr->route, arg, JK_SHM_STR_SIZ);
                             sync_needed = JK_TRUE;
                             if (!wr->domain[0]) {
                                 char * id_domain = strchr(wr->route, '.');
@@ -3829,7 +3829,8 @@ static void commit_all_members(jk_ws_service_t *s,
                 }
                 else if (!strcmp(attribute, JK_STATUS_ARG_LBM_REDIRECT)) {
                     if (rv == JK_TRUE) {
-                        if (jk_check_attribute_length("redirect", arg, l) == JK_FALSE) {
+                        int ret = jk_shm_str_init_ne(wr->redirect, arg, "redirect", l);
+                        if (ret == -1) {
                             const char *msg = "Update failed (at least partially): new redirect '%s' "
                                               "too long for sub worker '%s', see log file for details.";
                             size_t size = strlen(msg) + strlen(arg) + strlen(wr->name) + 1;
@@ -3837,18 +3838,18 @@ static void commit_all_members(jk_ws_service_t *s,
                             snprintf(p->msg, size, msg, arg, aw->name);
                             rc = JK_FALSE;
                         }
-                        else if (strncmp(wr->redirect, arg, JK_SHM_STR_SIZ)) {
+                        else if (ret != 0) {
                             jk_log(l, JK_LOG_INFO,
                                    "Status worker '%s' changing 'redirect' for sub worker '%s' of lb worker '%s' from '%s' to '%s'",
                                    w->name, wr->name, name, wr->redirect, arg);
-                            strncpy(wr->redirect, arg, JK_SHM_STR_SIZ);
                             sync_needed = JK_TRUE;
                         }
                     }
                 }
                 else if (!strcmp(attribute, JK_STATUS_ARG_LBM_DOMAIN)) {
                     if (rv == JK_TRUE) {
-                        if (jk_check_attribute_length("domain", arg, l) == JK_FALSE) {
+                        int ret = jk_shm_str_init_ne(wr->domain, arg, "domain", l);
+                        if (ret == -1) {
                             const char *msg = "Update failed (at least partially): new domain '%s' "
                                               "too long for sub worker '%s', see log file for details.";
                             size_t size = strlen(msg) + strlen(arg) + strlen(wr->name) + 1;
@@ -3856,11 +3857,10 @@ static void commit_all_members(jk_ws_service_t *s,
                             snprintf(p->msg, size, msg, arg, aw->name);
                             rc = JK_FALSE;
                         }
-                        else if (strncmp(wr->domain, arg, JK_SHM_STR_SIZ)) {
+                        else if (ret != 0) {
                             jk_log(l, JK_LOG_INFO,
                                    "Status worker '%s' changing 'domain' for sub worker '%s' of lb worker '%s' from '%s' to '%s'",
                                    w->name, wr->name, name, wr->domain, arg);
-                            strncpy(wr->domain, arg, JK_SHM_STR_SIZ);
                             sync_needed = JK_TRUE;
                         }
                     }
diff --git a/native/common/jk_uri_worker_map.c b/native/common/jk_uri_worker_map.c
index 6127f352e..8ee722aaf 100644
--- a/native/common/jk_uri_worker_map.c
+++ b/native/common/jk_uri_worker_map.c
@@ -1190,7 +1190,7 @@ const char *map_uri_to_worker_ext(jk_uri_worker_map_t *uw_map,
                    vhost, JK_MAX_URI_LEN - off);
         }
         else {
-            strncpy(&url[off], vhost, vhost_len + 1);
+            memcpy(&url[off], vhost, vhost_len + 1);
             if (JK_IS_DEBUG_LEVEL(l)) {
                 jk_log(l, JK_LOG_DEBUG,
                        "Prefixing mapping uri with vhost '%s'", vhost);
diff --git a/native/common/jk_util.c b/native/common/jk_util.c
index f4836cd89..f64d47659 100644
--- a/native/common/jk_util.c
+++ b/native/common/jk_util.c
@@ -446,15 +446,15 @@ void jk_set_time_fmt(jk_logger_t *l, const char *jk_log_fmt)
             if (offset + len < JK_TIME_MAX_SIZE) {
                 l->log_fmt_type = JK_TIME_SUBSEC_MILLI;
                 l->log_fmt_offset = offset;
-                strncpy(l->log_fmt_subsec, jk_log_fmt, offset);
-                strncpy(l->log_fmt_subsec + offset, JK_TIME_PATTERN_MILLI, len);
-                strncpy(l->log_fmt_subsec + offset + len,
-                        s + strlen(JK_TIME_CONV_MILLI),
-                        JK_TIME_MAX_SIZE - offset - len - 1);
+                memcpy(l->log_fmt_subsec, jk_log_fmt, offset);
+                memcpy(l->log_fmt_subsec + offset, JK_TIME_PATTERN_MILLI, len);
+                memcpy(l->log_fmt_subsec + offset + len,
+                       s + strlen(JK_TIME_CONV_MILLI),
+                       JK_TIME_MAX_SIZE - offset - len - 1);
                 /* Now we put a stop mark into the string to make it's length
                  * at most JK_TIME_MAX_SIZE-1 plus terminating '\0'.
                  */
-                l->log_fmt_subsec[JK_TIME_MAX_SIZE-1] = '\0';
+                l->log_fmt_subsec[JK_TIME_MAX_SIZE - 1] = '\0';
                 l->log_fmt_size = strlen(l->log_fmt_subsec);
             }
         }
@@ -471,15 +471,15 @@ void jk_set_time_fmt(jk_logger_t *l, const char *jk_log_fmt)
             if (offset + len < JK_TIME_MAX_SIZE) {
                 l->log_fmt_type = JK_TIME_SUBSEC_MICRO;
                 l->log_fmt_offset = offset;
-                strncpy(l->log_fmt_subsec, jk_log_fmt, offset);
-                strncpy(l->log_fmt_subsec + offset, JK_TIME_PATTERN_MICRO, len);
-                strncpy(l->log_fmt_subsec + offset + len,
-                        s + strlen(JK_TIME_CONV_MICRO),
-                        JK_TIME_MAX_SIZE - offset - len - 1);
+                memcpy(l->log_fmt_subsec, jk_log_fmt, offset);
+                memcpy(l->log_fmt_subsec + offset, JK_TIME_PATTERN_MICRO, len);
+                memcpy(l->log_fmt_subsec + offset + len,
+                       s + strlen(JK_TIME_CONV_MICRO),
+                       JK_TIME_MAX_SIZE - offset - len - 1);
                 /* Now we put a stop mark into the string to make it's length
                  * at most JK_TIME_MAX_SIZE-1 plus terminating '\0'.
                  */
-                l->log_fmt_subsec[JK_TIME_MAX_SIZE-1] = '\0';
+                l->log_fmt_subsec[JK_TIME_MAX_SIZE - 1] = '\0';
                 l->log_fmt_size = strlen(l->log_fmt_subsec);
             }
         }
@@ -835,20 +835,6 @@ int jk_log(jk_log_context_t *log_ctx,
     return rc;
 }
 
-int jk_check_attribute_length(const char *name, const char *value,
-                              jk_log_context_t *l)
-{
-    size_t len = strlen(value);
-    if (len > JK_MAX_NAME_LEN) {
-        jk_log(l, JK_LOG_ERROR,
-               "Worker %s '%s' is %d bytes too long, "
-               "a maximum of %d bytes is supported",
-               name, value, len - JK_MAX_NAME_LEN, JK_MAX_NAME_LEN);
-        return JK_FALSE;
-    }
-    return JK_TRUE;
-}
-
 const char *jk_get_worker_type(jk_map_t *m, const char *wname)
 {
     char buf[PARAM_BUFFER_SIZE];
diff --git a/native/common/jk_util.h b/native/common/jk_util.h
index 96d176af2..eff8c82f3 100644
--- a/native/common/jk_util.h
+++ b/native/common/jk_util.h
@@ -57,9 +57,6 @@ int jk_log(jk_log_context_t *log_ctx,
            const char *file, int line, const char *funcname, int level,
            const char *fmt, ...);
 
-int jk_check_attribute_length(const char *name, const char *value,
-                              jk_log_context_t *log_ctx);
-
 const char *jk_get_worker_host(jk_map_t *m, const char *wname, const char *def);
 
 const char *jk_get_worker_source(jk_map_t *m, const char *wname, const char *def);
diff --git a/native/common/jk_worker.c b/native/common/jk_worker.c
index e6c4943e5..d082a61bb 100644
--- a/native/common/jk_worker.c
+++ b/native/common/jk_worker.c
@@ -128,10 +128,6 @@ int wc_create_worker(const char *name, int use_map,
 {
     JK_TRACE_ENTER(l);
 
-    if (jk_check_attribute_length("name", name, l) == JK_FALSE) {
-        JK_TRACE_EXIT(l);
-        return JK_FALSE;
-    }
     if (rc) {
         const char *type = jk_get_worker_type(init_data, name);
         worker_factory fac = get_factory_for(type);
diff --git a/xdocs/miscellaneous/changelog.xml b/xdocs/miscellaneous/changelog.xml
index 274c54933..a0cd126f9 100644
--- a/xdocs/miscellaneous/changelog.xml
+++ b/xdocs/miscellaneous/changelog.xml
@@ -42,6 +42,10 @@
 </section>
 <section name="Changes between 1.2.48 and 1.2.49">
   <changelog>
+    <fix>
+      Common: Fix compiler warning when nitializing and copying fixed length
+      strings. (rjung)
+    </fix>
     <update>
       IIS: Set default request id as a GUID.
       It can also be taken from an arbitrary request


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org