patch-lib_relocatable_c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. $OpenBSD: patch-lib_relocatable_c,v 1.3 2011/09/02 15:44:46 naddy Exp $
  2. --- lib/relocatable.c.orig Thu Sep 1 18:08:15 2011
  3. +++ lib/relocatable.c Thu Sep 1 18:21:29 2011
  4. @@ -446,16 +446,20 @@ relocate (const char *pathname)
  5. if (orig_prefix != NULL && curr_prefix != NULL
  6. && strncmp (pathname, orig_prefix, orig_prefix_len) == 0)
  7. {
  8. + char *result;
  9. + size_t len;
  10. +
  11. if (pathname[orig_prefix_len] == '\0')
  12. {
  13. /* pathname equals orig_prefix. */
  14. - char *result = (char *) xmalloc (strlen (curr_prefix) + 1);
  15. + len = strlen (curr_prefix) + 1;
  16. + result = (char *) xmalloc (len);
  17. #ifdef NO_XMALLOC
  18. if (result != NULL)
  19. #endif
  20. {
  21. - strcpy (result, curr_prefix);
  22. + strlcpy (result, curr_prefix, len);
  23. return result;
  24. }
  25. }
  26. @@ -463,15 +467,16 @@ relocate (const char *pathname)
  27. {
  28. /* pathname starts with orig_prefix. */
  29. const char *pathname_tail = &pathname[orig_prefix_len];
  30. - char *result =
  31. - (char *) xmalloc (curr_prefix_len + strlen (pathname_tail) + 1);
  32. + len = curr_prefix_len + strlen (pathname_tail) + 1;
  33. + result = (char *) xmalloc (len);
  34. #ifdef NO_XMALLOC
  35. if (result != NULL)
  36. #endif
  37. {
  38. memcpy (result, curr_prefix, curr_prefix_len);
  39. - strcpy (result + curr_prefix_len, pathname_tail);
  40. + result[curr_prefix_len] = '\0';
  41. + strlcat (result, pathname_tail, len);
  42. return result;
  43. }
  44. }