$OpenBSD: patch-lib_relocatable_c,v 1.3 2011/09/02 15:44:46 naddy Exp $ --- lib/relocatable.c.orig Thu Sep 1 18:08:15 2011 +++ lib/relocatable.c Thu Sep 1 18:21:29 2011 @@ -446,16 +446,20 @@ relocate (const char *pathname) if (orig_prefix != NULL && curr_prefix != NULL && strncmp (pathname, orig_prefix, orig_prefix_len) == 0) { + char *result; + size_t len; + if (pathname[orig_prefix_len] == '\0') { /* pathname equals orig_prefix. */ - char *result = (char *) xmalloc (strlen (curr_prefix) + 1); + len = strlen (curr_prefix) + 1; + result = (char *) xmalloc (len); #ifdef NO_XMALLOC if (result != NULL) #endif { - strcpy (result, curr_prefix); + strlcpy (result, curr_prefix, len); return result; } } @@ -463,15 +467,16 @@ relocate (const char *pathname) { /* pathname starts with orig_prefix. */ const char *pathname_tail = &pathname[orig_prefix_len]; - char *result = - (char *) xmalloc (curr_prefix_len + strlen (pathname_tail) + 1); + len = curr_prefix_len + strlen (pathname_tail) + 1; + result = (char *) xmalloc (len); #ifdef NO_XMALLOC if (result != NULL) #endif { memcpy (result, curr_prefix, curr_prefix_len); - strcpy (result + curr_prefix_len, pathname_tail); + result[curr_prefix_len] = '\0'; + strlcat (result, pathname_tail, len); return result; } }