lib/util_unistr.c: Off-by-one fix for dos_PutUniStr from John Reilly jreilly@hp.com.
authorJeremy Allison <jra@samba.org>
Fri, 23 Jun 2000 17:31:38 +0000 (17:31 +0000)
committerJeremy Allison <jra@samba.org>
Fri, 23 Jun 2000 17:31:38 +0000 (17:31 +0000)
Memory leak fix for new sec_ctx code (sorry Tim :-).
Jeremy.
(This used to be commit edaf49c66d5a5ccf6689b358c301e208599a468f)

source3/lib/util_unistr.c
source3/smbd/sec_ctx.c

index d4a159a28e7a47485b1e47a88264821ed1f8ae13..1c13ff2758e5b9c18c1201baebcb594e133660d7 100644 (file)
@@ -55,7 +55,7 @@ static uint16 *ucs2_to_unixcp;
 size_t dos_PutUniCode(char *dst,const char *src, ssize_t len, BOOL null_terminate)
 {
        size_t ret = 0;
-       while (*src && (len > 2)) {
+       while (*src && (len >= 2)) {
                size_t skip = get_character_len(*src);
                smb_ucs2_t val = (*src & 0xff);
 
index e3aac77d8e4f5825174e87e53ea3aa92015f6075..bbd801d76b31eb80c961f5b66222c0f5e810d573 100644 (file)
@@ -184,11 +184,15 @@ void set_sec_ctx(uid_t uid, gid_t gid, int ngroups, gid_t *groups)
 
 #ifdef HAVE_SETGROUPS
        sys_setgroups(ngroups, groups);
+#endif
 
        sec_ctx_stack[sec_ctx_stack_ndx].ngroups = ngroups;
+
+       if (sec_ctx_stack[sec_ctx_stack_ndx].groups != NULL)
+               free(sec_ctx_stack[sec_ctx_stack_ndx].groups);
+
        sec_ctx_stack[sec_ctx_stack_ndx].groups = 
                memdup(groups, sizeof(gid_t) * ngroups);
-#endif
 
        become_id(uid, gid);