summaryrefslogtreecommitdiff
path: root/security/policykit/patches/patch-aj
blob: 150de873a6a127f42c9dd156af17d95c854233bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
$NetBSD: patch-aj,v 1.1 2008/11/23 22:28:23 jmcneill Exp $

--- src/kit/kit-string.c.orig	2008-05-30 17:24:44.000000000 -0400
+++ src/kit/kit-string.c	2008-07-24 01:21:34.000000000 -0400
@@ -123,13 +123,18 @@ static char
         if ( !s )
                 return NULL;
 
-        if ( strlen(s) > n )
-                nAvail = n + 1;
-        else
-                nAvail = strlen(s) + 1;
-        p = malloc ( nAvail );
+        if (memchr(s, '\0', n) != NULL) {
+                nAvail = strlen(s);
+                if ( nAvail > n )
+                        nAvail = n;
+        } else {
+                nAvail = n;
+        }
+        p = malloc ( nAvail + 1 );
+        if (p == NULL)
+                return NULL;
         memcpy ( p, s, nAvail );
-        p[nAvail - 1] = '\0';
+        p[nAvail] = '\0';
 
         return p;
 }