From: Junio C Hamano Date: Fri, 03 Aug 2007 06:29:10 GMT Subject: Re: [PATCH] Fix unterminated string in set_work_tree and improve error handling Message-ID: <7v7iodqgg9.fsf@assigned-by-dhcp.cox.net> In-Reply-To: <81b0412b0708022247s1116f66al1e8751f33bcae581@mail.gmail.com> "Alex Riesen" writes: >> >> Consolidating two of your patches, would this be Ok? >> > >> > Yes, but you may consider replacing strncpy with strlcpy: >> > >> >> + memcpy(dir_buffer, dir, len - suffix_len); >> >> + dir_buffer[len - suffix_len] = '\0'; >> > >> > strlcpy(dir_buffer, dir, len - suffix_len + 1); >> >> Does that buy us that much? Before going to that codepath, we >> have made sure the result fits, haven't we? I sense you haven't read my replacement patch (Dscho Acked it). I am talking about this part: + if (len > suffix_len && + !strcmp(dir + len - suffix_len, "/" DEFAULT_GIT_DIR_ENVIRONMENT)) { + if ((len - suffix_len) >= sizeof(dir_buffer)) + die("directory name too long"); + memcpy(dir_buffer, dir, len - suffix_len); + dir_buffer[len - suffix_len] = '\0';