1
1

Added memory error checks for option functions.

git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@322 7dcaeef0-15fb-0310-b436-a5af3365683c
Этот коммит содержится в:
Andreas Schneider 2009-04-01 19:54:41 +00:00
родитель 54ce86e3b1
Коммит 8bcd65193c
2 изменённых файлов: 35 добавлений и 4 удалений

Просмотреть файл

@ -50,7 +50,13 @@
*/
SSH_OPTIONS *ssh_options_new(void) {
SSH_OPTIONS *option=malloc(sizeof(SSH_OPTIONS));
SSH_OPTIONS *option;
option = malloc(sizeof(SSH_OPTIONS));
if (options == NULL) {
return NULL;
}
memset(option,0,sizeof(SSH_OPTIONS));
option->port=22; /* set the default port */
option->fd=-1;
@ -82,8 +88,14 @@ void ssh_options_set_port(SSH_OPTIONS *opt, unsigned int port){
* \see ssh_session_connect()
*/
SSH_OPTIONS *ssh_options_copy(SSH_OPTIONS *opt){
SSH_OPTIONS *ret=ssh_options_new();
SSH_OPTIONS *ret;
int i;
ret = ssh_options_new();
if (ret == NULL) {
return NULL;
}
ret->fd=opt->fd;
ret->port=opt->port;
if(opt->username)
@ -331,6 +343,9 @@ int ssh_options_default_username(SSH_OPTIONS *opt){
DWORD Size = 0;
GetUserName(NULL, &Size); //Get Size
user = malloc(Size);
if (user == NULL) {
return -1;
}
if (GetUserName(user, &Size)){
opt->username=user;
return 0;
@ -460,7 +475,7 @@ int ssh_options_getopt(SSH_OPTIONS *options, int *argcptr, char **argv){
char *cipher=NULL;
char *localaddr=NULL;
char *identity=NULL;
char **save=malloc(argc * sizeof(char *));
char **save = NULL;
int current=0;
#ifdef HAVE_SSH1
int ssh1=1;
@ -471,6 +486,12 @@ int ssh_options_getopt(SSH_OPTIONS *options, int *argcptr, char **argv){
int saveoptind=optind; /* need to save 'em */
int saveopterr=opterr;
save = malloc(argc * sizeof(char *));
if (save == NULL) {
return -1;
}
opterr=0; /* shut up getopt */
while(cont && ((i=getopt(argc,argv,"c:i:Cl:p:vb:rd12"))!=-1)){

Просмотреть файл

@ -170,10 +170,20 @@ SSH_SESSION *ssh_bind_accept(SSH_BIND *ssh_bind){
session=ssh_new();
session->server=1;
session->version=2;
session->options = ssh_options_copy(ssh_bind->options);
if (session->options == NULL) {
ssh_set_error(ssh_bind, SSH_FATAL, "No space left");
if (dsa)
private_key_free(dsa);
if (rsa)
private_key_free(rsa);
ssh_cleanup(session);
return NULL;
}
ssh_socket_free(session->socket);
session->socket=ssh_socket_new(session);
ssh_socket_set_fd(session->socket,fd);
session->options=ssh_options_copy(ssh_bind->options);
session->dsa_key=dsa;
session->rsa_key=rsa;
return session;