PolicyKit: Branch 'master'

David Zeuthen david at kemper.freedesktop.org
Tue Nov 6 12:58:05 PST 2007


 polkit/polkit-memory.c |   22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

New commits:
commit cb93ff93af3a319e183d3897b5c525df29092b52
Author: David Zeuthen <davidz at redhat.com>
Date:   Tue Nov 6 15:55:02 2007 -0500

    fix some unaligned access bugs

diff --git a/polkit/polkit-memory.c b/polkit/polkit-memory.c
index 5712a59..0383e9b 100644
--- a/polkit/polkit-memory.c
+++ b/polkit/polkit-memory.c
@@ -166,16 +166,17 @@ p_free (void *memory)
 char *
 p_strdup (const char *s)
 {
-        void *p;
+        char *p;
         size_t len;
 
-        len = strlen (s) + 1;
+        len = strlen (s);
 
         p = p_malloc (len + 1);
         if (p == NULL)
                 goto out;
 
-        memcpy (p, s, len + 1);
+        memcpy (p, s, len);
+        p[len] = '\0';
 
 out:
         return p;
@@ -197,18 +198,23 @@ out:
 char *
 p_strndup (const char *s, size_t n)
 {
-        void *p;
+        char *p;
         size_t len;
 
-        len = strlen (s) + 1;
-        if (len > n)
-                len = n;
+        for (len = 0; len < n; len++) {
+                if (s[len] == '\0')
+                        break;
+                if (len == n)
+                        break;
+        }
+
 
         p = p_malloc (len + 1);
         if (p == NULL)
                 goto out;
 
-        memcpy (p, s, len + 1);
+        memcpy (p, s, len);
+        p[len] = '\0';
 out:
         return p;
 }


More information about the hal-commit mailing list