diff options
author | Bob Beck <beck@cvs.openbsd.org> | 2003-05-12 04:13:43 +0000 |
---|---|---|
committer | Bob Beck <beck@cvs.openbsd.org> | 2003-05-12 04:13:43 +0000 |
commit | f7c70a2765bf16d8da2a70e5c69e1d4deb5ca11e (patch) | |
tree | 9c4bdc5917e63fa6a3d6359cc0204b27b11cf4d2 /gnu/lib/libreadline/complete.c | |
parent | 00fb027f4447a3d6e176e1486c52314080249dde (diff) |
strings in libreadline, again. this time with no abi change,
static builds still seem to work with this. ok deraadt@ tedu@
Diffstat (limited to 'gnu/lib/libreadline/complete.c')
-rw-r--r-- | gnu/lib/libreadline/complete.c | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/gnu/lib/libreadline/complete.c b/gnu/lib/libreadline/complete.c index fb48712a4e0..d5f983b0489 100644 --- a/gnu/lib/libreadline/complete.c +++ b/gnu/lib/libreadline/complete.c @@ -459,7 +459,7 @@ print_filename (to_print, full_pathname) } #else char *s, c, *new_full_pathname; - int extension_char, slen, tlen; + int extension_char; for (s = to_print; *s; s++) { @@ -485,16 +485,9 @@ print_filename (to_print, full_pathname) s = tilde_expand (full_pathname && *full_pathname ? full_pathname : "/"); if (rl_directory_completion_hook) (*rl_directory_completion_hook) (&s); - - slen = strlen (s); - tlen = strlen (to_print); - new_full_pathname = xmalloc (slen + tlen + 2); - strcpy (new_full_pathname, s); - new_full_pathname[slen] = '/'; - strcpy (new_full_pathname + slen + 1, to_print); - + if (asprintf(&new_full_pathname, "%s/%s", s, to_print) == -1) + memory_error_and_abort("asprintf"); extension_char = stat_char (new_full_pathname); - free (new_full_pathname); to_print[-1] = c; } @@ -522,10 +515,11 @@ rl_quote_filename (s, rtype, qcp) char *qcp; { char *r; + int len = strlen(s) + 2; - r = xmalloc (strlen (s) + 2); + r = xmalloc (len); *r = *rl_completer_quote_characters; - strcpy (r + 1, s); + strlcpy (r + 1, s, len - 1); if (qcp) *qcp = *rl_completer_quote_characters; return r; @@ -820,8 +814,9 @@ compute_lcd_of_matches (match_list, matches, text) value of matches[0]. */ if (low == 0 && text && *text) { - match_list[0] = xmalloc (strlen (text) + 1); - strcpy (match_list[0], text); + match_list[0] = strdup(text); + if (match_list[0] == NULL) + memory_error_and_abort("strdup"); } else { @@ -1452,11 +1447,12 @@ username_completion_function (text, state) } else { - value = xmalloc (2 + strlen (entry->pw_name)); + int len = 2 + strlen(entry->pw_name); + value = xmalloc (len); *value = *text; - strcpy (value + first_char_loc, entry->pw_name); + strlcpy (value + first_char_loc, entry->pw_name, len - first_char_loc); if (first_char == '~') rl_filename_completion_desired = 1; @@ -1499,6 +1495,7 @@ filename_completion_function (text, state) FREE (users_dirname); filename = savestring (text); + filename_len = strlen(filename); if (*text == 0) text = "."; dirname = savestring (text); @@ -1513,14 +1510,15 @@ filename_completion_function (text, state) if (temp) { - strcpy (filename, ++temp); + strlcpy (filename, ++temp, filename_len); *temp = '\0'; } #if defined (__MSDOS__) /* searches from current directory on the drive */ else if (isalpha (dirname[0]) && dirname[1] == ':') { - strcpy (filename, dirname + 2); + /* XXX DOS strlcpy anyone? */ + strlcpy (filename, dirname + 2, filename_len); dirname[2] = '\0'; } #endif @@ -1625,11 +1623,13 @@ filename_completion_function (text, state) /* dirname && (strcmp (dirname, ".") != 0) */ if (dirname && (dirname[0] != '.' || dirname[1])) { + int templen; if (rl_complete_with_tilde_expansion && *users_dirname == '~') { dirlen = strlen (dirname); - temp = xmalloc (2 + dirlen + D_NAMLEN (entry)); - strcpy (temp, dirname); + templen = 2 + dirlen + D_NAMLEN (entry); + temp = xmalloc (templen); + strlcpy (temp, dirname, templen); /* Canonicalization cuts off any final slash present. We may need to add it back. */ if (dirname[dirlen - 1] != '/') @@ -1641,11 +1641,12 @@ filename_completion_function (text, state) else { dirlen = strlen (users_dirname); - temp = xmalloc (1 + dirlen + D_NAMLEN (entry)); - strcpy (temp, users_dirname); + templen = 1 + dirlen + D_NAMLEN (entry); + temp = xmalloc (templen); + strlcpy (temp, users_dirname, templen); } - strcpy (temp + dirlen, entry->d_name); + strlcat (temp, entry->d_name, templen); } else temp = savestring (entry->d_name); |