From 399041180ffccd613119f2bd41cf7563e675600d Mon Sep 17 00:00:00 2001 From: Aris Adamantiadis Date: Sat, 10 Oct 2009 16:25:40 +0200 Subject: [PATCH] resolve callback crash --- examples/sample.c | 17 ++++++++--------- include/libssh/callbacks.h | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/examples/sample.c b/examples/sample.c index 9ed2470b..c0084c49 100644 --- a/examples/sample.c +++ b/examples/sample.c @@ -40,6 +40,7 @@ char *user; int sftp; char *cmds[MAXCMD]; struct termios terminal; + void do_sftp(ssh_session session); static int auth_callback(const char *prompt, char *buf, size_t len, @@ -68,6 +69,11 @@ static int auth_callback(const char *prompt, char *buf, size_t len, return 0; } +struct ssh_callbacks_struct cb = { + .auth_function=auth_callback, + .userdata=NULL +}; + static void add_cmd(char *cmd){ int n; for(n=0;cmds[n] && (nauth_function = auth_callback; - cb->userdata = NULL; - - ssh_callbacks_init(cb); - ssh_set_callbacks(session, cb); + ssh_callbacks_init(&cb); + ssh_set_callbacks(session,&cb); if(ssh_options_getopt(session, &argc, argv)) { fprintf(stderr, "error parsing command line :%s\n", diff --git a/include/libssh/callbacks.h b/include/libssh/callbacks.h index 25f071a7..1adaaa35 100644 --- a/include/libssh/callbacks.h +++ b/include/libssh/callbacks.h @@ -79,7 +79,7 @@ typedef struct ssh_callbacks_struct * ssh_callbacks; * evolves with time. */ #define ssh_callbacks_init(p) do {\ - p->size=sizeof(*p); \ + (p)->size=sizeof(*(p)); \ } while(0); LIBSSH_API int ssh_set_callbacks(ssh_session session, ssh_callbacks cb);