From 77743b75f41bd353c09da6a740562d621ed9382d Mon Sep 17 00:00:00 2001 From: Aris Adamantiadis Date: Tue, 4 Mar 2008 04:25:48 +0000 Subject: fixed null pointer into options and ssh_set_error() git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@138 7dcaeef0-15fb-0310-b436-a5af3365683c --- include/libssh/priv.h | 16 ++++++++-------- libssh/options.c | 12 ++++++------ sample.c | 6 ++++-- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/include/libssh/priv.h b/include/libssh/priv.h index 08f9744d..685630bd 100644 --- a/include/libssh/priv.h +++ b/include/libssh/priv.h @@ -205,7 +205,15 @@ typedef struct signature_struct { #endif } SIGNATURE; + +struct error_struct { +/* error handling */ + int error_code; + char error_buffer[ERROR_BUFFERLEN]; +}; + struct ssh_options_struct { + struct error_struct error; char *banner; /* explicit banner to send */ char *username; char *host; @@ -275,14 +283,6 @@ struct channel_struct { int blocking; }; - -struct error_struct { -/* error handling */ - int error_code; - char error_buffer[ERROR_BUFFERLEN]; -}; - - struct ssh_session { struct error_struct error; struct socket *socket; diff --git a/libssh/options.c b/libssh/options.c index 28f05b7b..8c6c7253 100644 --- a/libssh/options.c +++ b/libssh/options.c @@ -275,11 +275,11 @@ void ssh_options_set_banner(SSH_OPTIONS *opt, char *banner){ */ int ssh_options_set_wanted_algos(SSH_OPTIONS *opt,int algo, char *list){ if(algo > SSH_LANG_S_C || algo < 0){ - ssh_set_error(NULL,SSH_REQUEST_DENIED,"algo %d out of range",algo); + ssh_set_error(opt,SSH_REQUEST_DENIED,"algo %d out of range",algo); return -1; } if( (!opt->use_nonexisting_algo) && !verify_existing_algo(algo,list)){ - ssh_set_error(NULL,SSH_REQUEST_DENIED,"Setting method : no algorithm " + ssh_set_error(opt,SSH_REQUEST_DENIED,"Setting method : no algorithm " "for method \"%s\" (%s)\n",ssh_kex_nums[algo],list); return -1; } @@ -289,7 +289,7 @@ int ssh_options_set_wanted_algos(SSH_OPTIONS *opt,int algo, char *list){ return 0; } -static char *get_username_from_uid(int uid){ +static char *get_username_from_uid(SSH_OPTIONS *opt, int uid){ struct passwd *pwd; char *user; while((pwd=getpwent())){ @@ -300,7 +300,7 @@ static char *get_username_from_uid(int uid){ } } endpwent(); - ssh_set_error(NULL,SSH_FATAL,"uid %d doesn't exist !",uid); + ssh_set_error(opt,SSH_FATAL,"uid %d doesn't exist !",uid); return NULL; } @@ -314,7 +314,7 @@ int ssh_options_default_username(SSH_OPTIONS *opt){ opt->username=strdup(user); return 0; } - user=get_username_from_uid(getuid()); + user=get_username_from_uid(opt,getuid()); if(user){ opt->username=user; return 0; @@ -483,7 +483,7 @@ int ssh_options_getopt(SSH_OPTIONS *options, int *argcptr, char **argv){ save[current++]=argv[optind++]; if(usersa && usedss){ - ssh_set_error(NULL,SSH_FATAL,"either RSA or DSS must be chosen"); + ssh_set_error(options,SSH_FATAL,"either RSA or DSS must be chosen"); cont=0; } ssh_set_verbosity(debuglevel); diff --git a/sample.c b/sample.c index 9fef51ed..7baff76a 100644 --- a/sample.c +++ b/sample.c @@ -379,8 +379,10 @@ int main(int argc, char **argv){ unsigned char hash[MD5_DIGEST_LEN]; options=ssh_options_new(); - if(ssh_options_getopt(options,&argc, argv)) - usage(); + if(ssh_options_getopt(options,&argc, argv)){ + fprintf(stderr,"error parsing command line :%s\n",ssh_get_error(options)); + usage(); + } opts(argc,argv); signal(SIGTERM,do_exit); if(user) -- cgit v1.2.3