summaryrefslogtreecommitdiffstats
path: root/libssh/keyfiles.c
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-03-29 15:19:45 +0000
committerAndreas Schneider <mail@cynapses.org>2009-03-29 15:19:45 +0000
commit84430b22771ae368267ce20e7c2ef612ada42c7c (patch)
tree3536250f4936713d31593e330f9edafd6058021e /libssh/keyfiles.c
parent4ab28a049f96e2186a91bf62fbf98b8f8faa0f72 (diff)
downloadlibssh-84430b22771ae368267ce20e7c2ef612ada42c7c.tar.gz
libssh-84430b22771ae368267ce20e7c2ef612ada42c7c.tar.xz
libssh-84430b22771ae368267ce20e7c2ef612ada42c7c.zip
Improve the lowercase function and free memory allocated by lowercase().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@304 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh/keyfiles.c')
-rw-r--r--libssh/keyfiles.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/libssh/keyfiles.c b/libssh/keyfiles.c
index ccf59e3..99510c2 100644
--- a/libssh/keyfiles.c
+++ b/libssh/keyfiles.c
@@ -786,15 +786,30 @@ static int alldigits(char *s)
/** \addtogroup ssh_session
* @{ */
-/** \brief lowercases a string
- * \param string string to lowercase
- * \internal
+/**
+ * @brief Lowercase a string.
+ *
+ * @param str String to lowercase.
+ *
+ * @return The lowered string or NULL on error.
+ *
+ * @internal
*/
-static void lowercase(char *string){
- for (;*string;string++){
- *string=tolower(*string);
- }
+static char *lowercase(const char* str) {
+ char *p = 0;
+ char *new = strdup(str);
+
+ if((str == NULL) || (new == NULL)) {
+ return NULL;
+ }
+
+ for (p = new; *p; p++) {
+ *p = tolower(*p);
+ }
+
+ return new;
}
+
/** \brief frees a token array
* \internal
*/
@@ -1021,8 +1036,7 @@ int ssh_is_server_known(SSH_SESSION *session){
leave_function();
return SSH_SERVER_ERROR;
}
- host=strdup(session->options->host);
- lowercase(host);
+ host = lowercase(session->options->host);
do {
tokens=ssh_get_knownhost_line(session,&file,session->options->known_hosts_file,&type);
//
@@ -1059,6 +1073,7 @@ int ssh_is_server_known(SSH_SESSION *session){
}
}
} while (1);
+ SAFE_FREE(host);
/* Return the current state at end of file */
leave_function();
return ret;