Code

copy_gecos: fix not adding nlen to len when processing "&"
authorRafael Gieschke <rafael@gieschke.de>
Mon, 16 May 2011 20:08:21 +0000 (22:08 +0200)
committerJunio C Hamano <gitster@pobox.com>
Wed, 18 May 2011 04:27:19 +0000 (21:27 -0700)
nlen has to be added to len when inserting (capitalized) pw_name as
substitution for "&" in pw_gecos. Otherwise, pw_gecos will be truncated
and data might be written beyond name+sz.

Signed-off-by: Rafael Gieschke <rafael@gieschke.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
ident.c

diff --git a/ident.c b/ident.c
index 9e2438826dfce158e04549933d5c588dd6abcf5c..4232084208943c0772e394cfcff2328fb04493af 100644 (file)
--- a/ident.c
+++ b/ident.c
@@ -34,6 +34,7 @@ static void copy_gecos(const struct passwd *w, char *name, size_t sz)
                        *dst++ = toupper(*w->pw_name);
                        memcpy(dst, w->pw_name + 1, nlen - 1);
                        dst += nlen - 1;
+                       len += nlen;
                }
        }
        if (len < sz)