1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-11-30 13:01:23 +03:00

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
This commit is contained in:
Andreas Schneider
2009-03-29 15:19:45 +00:00
parent 4ab28a049f
commit 84430b2277

View File

@@ -786,15 +786,30 @@ static int alldigits(char *s)
/** \addtogroup ssh_session /** \addtogroup ssh_session
* @{ */ * @{ */
/** \brief lowercases a string /**
* \param string string to lowercase * @brief Lowercase a string.
* \internal *
* @param str String to lowercase.
*
* @return The lowered string or NULL on error.
*
* @internal
*/ */
static void lowercase(char *string){ static char *lowercase(const char* str) {
for (;*string;string++){ char *p = 0;
*string=tolower(*string); 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 /** \brief frees a token array
* \internal * \internal
*/ */
@@ -1021,8 +1036,7 @@ int ssh_is_server_known(SSH_SESSION *session){
leave_function(); leave_function();
return SSH_SERVER_ERROR; return SSH_SERVER_ERROR;
} }
host=strdup(session->options->host); host = lowercase(session->options->host);
lowercase(host);
do { do {
tokens=ssh_get_knownhost_line(session,&file,session->options->known_hosts_file,&type); 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); } while (1);
SAFE_FREE(host);
/* Return the current state at end of file */ /* Return the current state at end of file */
leave_function(); leave_function();
return ret; return ret;