Attention is currently required from: Arne Schwabe, Răzvan Cojocaru.

Hello Arne Schwabe, Răzvan Cojocaru,

I'd like you to reexamine a change. Please visit

    https://gerrit.openvpn.net/c/openvpn/+/1996?usp=email

to look at the new patch set (#3).


Change subject: Replace strncat with strlcat
......................................................................

Replace strncat with strlcat

Generally much better API. Not a straight-forward
replacement in many cases, trying to improve the
code generally.

Change-Id: I61e29dd2af9302b240c93735179d43c72e37b335
Signed-off-by: Frank Lichtenheld <[email protected]>
---
M src/openvpn/misc.c
M src/openvpn/options_parse.c
M src/openvpn/status.c
M src/openvpn/xkey_helper.c
M src/plugins/auth-pam/utils.c
5 files changed, 25 insertions(+), 25 deletions(-)


  git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/96/1996/3

diff --git a/src/openvpn/misc.c b/src/openvpn/misc.c
index a75bd8f..b9cc6a2 100644
--- a/src/openvpn/misc.c
+++ b/src/openvpn/misc.c
@@ -437,12 +437,11 @@
                     }
                     else
                     {
-                        if (strlen(up->password) + strlen(response) >= 
USER_PASS_LEN)
+                        if (strlcat(up->password, response, USER_PASS_LEN) >= 
USER_PASS_LEN)
                         {
                             msg(M_FATAL,
                                 "ERROR: could not concatenate 
password/static_response: string too long");
                         }
-                        strncat(up->password, response, USER_PASS_LEN - 
strlen(up->password) - 1);
                     }
                 }
 #endif /* ifdef ENABLE_MANAGEMENT */
diff --git a/src/openvpn/options_parse.c b/src/openvpn/options_parse.c
index 12934ab..3d893d4 100644
--- a/src/openvpn/options_parse.c
+++ b/src/openvpn/options_parse.c
@@ -244,10 +244,7 @@
     else if (is->type == IS_TYPE_BUF)
     {
         bool status = buf_parse(is->u.multiline, '\n', line, size);
-        if ((int)strlen(line) + 1 < size)
-        {
-            strcat(line, "\n");
-        }
+        strlcat(line, "\n", size);
         return status;
     }
     else
diff --git a/src/openvpn/status.c b/src/openvpn/status.c
index c7d375b..981bb23 100644
--- a/src/openvpn/status.c
+++ b/src/openvpn/status.c
@@ -234,14 +234,11 @@

         if (so->fd >= 0 && !so->errors)
         {
-            strcat(buf, "\n");
-            ssize_t len = strlen(buf);
-            if (len > 0)
+            size_t len = strlcat(buf, "\n", sizeof(buf));
+            ASSERT(len < sizeof(buf));
+            if (write(so->fd, buf, (unsigned int)len) != (ssize_t)len)
             {
-                if (write(so->fd, buf, (unsigned int)len) != len)
-                {
-                    so->errors = true;
-                }
+                so->errors = true;
             }
         }

diff --git a/src/openvpn/xkey_helper.c b/src/openvpn/xkey_helper.c
index 1149c7b..6908cbb 100644
--- a/src/openvpn/xkey_helper.c
+++ b/src/openvpn/xkey_helper.c
@@ -157,7 +157,7 @@
  * @param tbslen        len of data in dgst
  * @param sigalg        extra signature parameters
  *
- * @return              signature length or -1 on error.
+ * @return              1 on success or 0 on error.
  */
 int
 xkey_management_sign(void *unused, unsigned char *sig, size_t *siglen, const 
unsigned char *tbs,
@@ -247,7 +247,10 @@

     if (is_message)
     {
-        strncat(alg_str, ",data=message", sizeof(alg_str) - strlen(alg_str) - 
1);
+        if (strlcat(alg_str, ",data=message", sizeof(alg_str)) >= 
sizeof(alg_str))
+        {
+            return 0;
+        }
     }

     dmsg(D_LOW, "xkey management_sign: requesting sig with algorithm <%s>", 
alg_str);
diff --git a/src/plugins/auth-pam/utils.c b/src/plugins/auth-pam/utils.c
index a4d2d0b..01cc4de 100644
--- a/src/plugins/auth-pam/utils.c
+++ b/src/plugins/auth-pam/utils.c
@@ -47,10 +47,11 @@
     }

     size_t tosearchlen = strlen(tosearch);
+    size_t searchforlen = strlen(searchfor);
     size_t replacewithlen = strlen(replacewith);
     size_t templen = tosearchlen * replacewithlen;

-    if (tosearchlen == 0 || strlen(searchfor) == 0 || replacewithlen == 0)
+    if (tosearchlen == 0 || searchforlen == 0 || replacewithlen == 0)
     {
         return NULL;
     }
@@ -65,23 +66,26 @@

     /* state: all parameters are valid */

-    const char *searching = tosearch;
-
-    char temp[templen + 1];
-    temp[0] = 0;
-
-    const char *scratch = strstr(searching, searchfor);
+    const char *scratch = strstr(tosearch, searchfor);
     if (!scratch)
     {
         return strdup(tosearch);
     }

+    const char *searching = tosearch;
+    char temp[templen + 1];
+    memset(temp, 0, sizeof(temp));
+    char *target = temp;
+
     while (scratch)
     {
-        strncat(temp, searching, (size_t)(scratch - searching));
-        strcat(temp, replacewith);
+        size_t skipped = (size_t)(scratch - searching);
+        memcpy(target, searching, skipped);
+        target += skipped;
+        memcpy(target, replacewith, replacewithlen);
+        target += replacewithlen;

-        searching = scratch + strlen(searchfor);
+        searching = scratch + searchforlen;
         scratch = strstr(searching, searchfor);
     }
     return strdup(temp);

--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/1996?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I61e29dd2af9302b240c93735179d43c72e37b335
Gerrit-Change-Number: 1996
Gerrit-PatchSet: 3
Gerrit-Owner: Frank Lichtenheld <[email protected]>
Gerrit-Reviewer: Arne Schwabe <[email protected]>
Gerrit-Reviewer: Răzvan Cojocaru <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: Răzvan Cojocaru <[email protected]>
Gerrit-Attention: Arne Schwabe <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Reply via email to