gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [gnunet] branch master updated (9228812ae -> 62fccf2d9)


From: gnunet
Subject: [GNUnet-SVN] [gnunet] branch master updated (9228812ae -> 62fccf2d9)
Date: Thu, 27 Jun 2019 11:43:22 +0200

This is an automated email from the git hooks/post-receive script.

lurchi pushed a change to branch master
in repository gnunet.

    from 9228812ae fix header check in param map
     new 6e75970db use GNUNET_strlcpy in strings.c too
     new f54e8c82d no null-termination necessary after GNUNET_strlcpy
     new 62fccf2d9 make GNUNET_strlcpy more flexible by using strnlen instead 
of strlen

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/exit/gnunet-helper-exit-windows.c | 19 +++++++------------
 src/util/strings.c                    | 21 ++++++++-------------
 src/vpn/gnunet-helper-vpn-windows.c   | 19 +++++++------------
 3 files changed, 22 insertions(+), 37 deletions(-)

diff --git a/src/exit/gnunet-helper-exit-windows.c 
b/src/exit/gnunet-helper-exit-windows.c
index 1e17ceaac..2e4b5f4a2 100644
--- a/src/exit/gnunet-helper-exit-windows.c
+++ b/src/exit/gnunet-helper-exit-windows.c
@@ -252,15 +252,12 @@ typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, 
PBOOL);
 
 
 /**
- * Like strlcpy but portable. The given string @a src is copied in full length
- * (until its null byte). The destination buffer is guaranteed to be
- * null-terminated.
+ * Like strlcpy but portable. The given string @a src is copied until its null
+ * byte or until @a n - 1 bytes have been read. The destination buffer is
+ * guaranteed to be null-terminated.
  *
- * to a destination buffer
- * and ensures that the destination string is null-terminated.
- *
- * @param dst destination of the copy
- * @param src source of the copy, must be null-terminated
+ * @param dst destination of the copy (must be @a n bytes long)
+ * @param src source of the copy (at most @a n - 1 bytes will be read)
  * @param n the length of the string to copy, including its terminating null
  *          byte
  * @return the length of the string that was copied, excluding the terminating
@@ -273,11 +270,10 @@ GNUNET_strlcpy(char *dst, const char *src, size_t n)
   size_t slen;
 
   GNUNET_assert (0 != n);
-  ret = strlen (src);
-  slen = GNUNET_MIN (ret, n - 1);
+  slen = strnlen (src, n - 1);
   memcpy (dst, src, slen);
   dst[slen] = '\0';
-  return ret;
+  return slen;
 }
 
 
@@ -1536,7 +1532,6 @@ main (int argc, char **argv)
     }
 
   GNUNET_strlcpy (hwid, argv[1], sizeof (hwid));
-  hwid[LINE_LEN - 1] = '\0';
 
   /*
    * We use our PID for finding/resolving the control-panel name of our virtual
diff --git a/src/util/strings.c b/src/util/strings.c
index d69244e83..d83c36ef8 100644
--- a/src/util/strings.c
+++ b/src/util/strings.c
@@ -203,15 +203,12 @@ GNUNET_STRINGS_byte_size_fancy (unsigned long long size)
 
 
 /**
- * Like strlcpy but portable. The given string @a src is copied in full length
- * (until its null byte). The destination buffer is guaranteed to be
- * null-terminated.
+ * Like strlcpy but portable. The given string @a src is copied until its null
+ * byte or until @a n - 1 bytes have been read. The destination buffer is
+ * guaranteed to be null-terminated.
  *
- * to a destination buffer
- * and ensures that the destination string is null-terminated.
- *
- * @param dst destination of the copy
- * @param src source of the copy, must be null-terminated
+ * @param dst destination of the copy (must be @a n bytes long)
+ * @param src source of the copy (at most @a n - 1 bytes will be read)
  * @param n the length of the string to copy, including its terminating null
  *          byte
  * @return the length of the string that was copied, excluding the terminating
@@ -224,11 +221,10 @@ GNUNET_strlcpy(char *dst, const char *src, size_t n)
   size_t slen;
 
   GNUNET_assert (0 != n);
-  ret = strlen (src);
-  slen = GNUNET_MIN (ret, n - 1);
+  slen = strnlen (src, n - 1);
   memcpy (dst, src, slen);
   dst[slen] = '\0';
-  return ret;
+  return slen;
 }
 
 
@@ -826,8 +822,7 @@ GNUNET_STRINGS_absolute_time_to_string (struct 
GNUNET_TIME_Absolute t)
         (uint8_t *) buf, &ssize);
     if (conved != (uint8_t *) buf)
     {
-      strncpy (buf, (char *) conved, sizeof (buf));
-      buf[255 - 1] = '\0';
+      GNUNET_strlcpy (buf, (char *) conved, sizeof (buf));
       free (conved);
     }
   }
diff --git a/src/vpn/gnunet-helper-vpn-windows.c 
b/src/vpn/gnunet-helper-vpn-windows.c
index 4ccecb873..ab72d71aa 100644
--- a/src/vpn/gnunet-helper-vpn-windows.c
+++ b/src/vpn/gnunet-helper-vpn-windows.c
@@ -252,15 +252,12 @@ typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, 
PBOOL);
 
 
 /**
- * Like strlcpy but portable. The given string @a src is copied in full length
- * (until its null byte). The destination buffer is guaranteed to be
- * null-terminated.
+ * Like strlcpy but portable. The given string @a src is copied until its null
+ * byte or until @a n - 1 bytes have been read. The destination buffer is
+ * guaranteed to be null-terminated.
  *
- * to a destination buffer
- * and ensures that the destination string is null-terminated.
- *
- * @param dst destination of the copy
- * @param src source of the copy, must be null-terminated
+ * @param dst destination of the copy (must be @a n bytes long)
+ * @param src source of the copy (at most @a n - 1 bytes will be read)
  * @param n the length of the string to copy, including its terminating null
  *          byte
  * @return the length of the string that was copied, excluding the terminating
@@ -273,11 +270,10 @@ GNUNET_strlcpy(char *dst, const char *src, size_t n)
   size_t slen;
 
   GNUNET_assert (0 != n);
-  ret = strlen (src);
-  slen = GNUNET_MIN (ret, n - 1);
+  slen = strnlen (src, n - 1);
   memcpy (dst, src, slen);
   dst[slen] = '\0';
-  return ret;
+  return slen;
 }
 
 
@@ -1533,7 +1529,6 @@ main (int argc, char **argv)
     }
 
   GNUNET_strlcpy (hwid, argv[1], sizeof (hwid));
-  hwid[LINE_LEN - 1] = '\0';
 
   /*
    * We use our PID for finding/resolving the control-panel name of our virtual

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]