diff --git a/binr/radare2/radare2.c b/binr/radare2/radare2.c index d029352721..dbaa3bddae 100644 --- a/binr/radare2/radare2.c +++ b/binr/radare2/radare2.c @@ -574,15 +574,16 @@ int main(int argc, char **argv, char **envp) { r_list_free (cmds); ///// if (r_config_get_i (r.config, "scr.prompt")) - if (run_rc && r_config_get_i (r.config, "cfg.fortunes")) { - r_core_cmd (&r, "fo", 0); - r_cons_flush (); - } + if (run_rc && r_config_get_i (r.config, "cfg.fortunes")) { + r_core_cmd (&r, "fo", 0); + r_cons_flush (); + } if (do_analysis) { r_core_cmd0 (&r, "aa"); r_cons_flush (); } - if (sandbox)r_config_set (r.config, "cfg.sandbox", "true"); + if (sandbox) + r_config_set (r.config, "cfg.sandbox", "true"); r.num->value = 0; if (patchfile) { @@ -591,10 +592,14 @@ int main(int argc, char **argv, char **envp) { for (;;) { #if USE_THREADS do { - if (r_core_prompt (&r, R_FALSE)<1) + int err = r_core_prompt (&r, R_FALSE); + if (err<1) { + // handle ^D break; + } if (lock) r_th_lock_enter (lock); if ((ret = r_core_prompt_exec (&r))==-1) { + break; // eprintf ("Invalid command\n"); } if (lock) r_th_lock_leave (lock); diff --git a/libr/cons/dietline.c b/libr/cons/dietline.c index 9380437ab1..8b8d9b6fe0 100644 --- a/libr/cons/dietline.c +++ b/libr/cons/dietline.c @@ -403,7 +403,9 @@ R_API char *r_line_readline_cb(RLineReadCallback cb, void *user) { #if USE_UTF8 utflen = r_line_readchar_utf8 ( (ut8*)buf, sizeof (buf)); - if (utflen <1) return NULL; + if (utflen <1) { + return NULL; + } buf[utflen] = 0; #else ch = r_line_readchar (); diff --git a/libr/cons/input.c b/libr/cons/input.c index 620d619fbc..3c2e607115 100644 --- a/libr/cons/input.c +++ b/libr/cons/input.c @@ -148,8 +148,9 @@ R_API int r_cons_fgets(char *buf, int len, int argc, const char **argv) { int mouse = r_cons_enable_mouse (R_FALSE); r_cons_enable_mouse (R_FALSE); r_cons_flush (); - if (cons->user_fgets) + if (cons->user_fgets) { RETURN (cons->user_fgets (buf, len)); + } *buf = '\0'; fflush (cons->fdin); if (color) { diff --git a/libr/core/core.c b/libr/core/core.c index 342f1d0cc9..8e1d23a2d2 100644 --- a/libr/core/core.c +++ b/libr/core/core.c @@ -426,7 +426,7 @@ R_API int r_core_fgets(char *buf, int len) { rli->completion.run = autocomplete; ptr = r_line_readline (); //CMDS, radare_argv); if (ptr == NULL) - return -2; + return -1; strncpy (buf, ptr, len); //free(ptr); // XXX leak return strlen (buf)+1; @@ -699,10 +699,12 @@ R_API int r_core_prompt(RCore *r, int sync) { } r_line_set_prompt (prompt); ret = r_cons_fgets (line, sizeof (line), 0, NULL); - if (ret == -2) return R_CORE_CMD_EXIT; - if (ret == -1) return R_FALSE; + if (ret == -2) return R_CORE_CMD_EXIT; // ^D + if (ret == -1) return R_FALSE; // FD READ ERROR r->num->value = rnv; - if (sync) return r_core_prompt_exec (r); + if (sync) { + return r_core_prompt_exec (r); + } free (r->cmdqueue); r->cmdqueue = strdup (line); return R_TRUE; diff --git a/libr/core/rtr.c b/libr/core/rtr.c index 933faef4f5..2b3954f08a 100644 --- a/libr/core/rtr.c +++ b/libr/core/rtr.c @@ -363,7 +363,7 @@ R_API void r_core_rtr_add(RCore *core, const char *_input) { timeout = r_config_get_i (core->config, "http.timeout"); strncpy (input, _input, sizeof (input)-4); /* Parse uri */ - if ((ptr = strstr(input, "tcp://"))) { + if ((ptr = strstr (input, "tcp://"))) { proto = RTR_PROT_TCP; host = ptr+6; } else if ((ptr = strstr(input, "http://"))) { diff --git a/libr/socket/socket.c b/libr/socket/socket.c index 1c53807a1b..25092878be 100644 --- a/libr/socket/socket.c +++ b/libr/socket/socket.c @@ -102,12 +102,12 @@ R_API RSocket *r_socket_new (int is_ssl) { signal (SIGPIPE, SIG_IGN); #endif s->local = 0; + s->fd = -1; #if HAVE_LIB_SSL if (is_ssl) { s->sfd = NULL; s->ctx = NULL; s->bio = NULL; - s->fd = -1; if (!SSL_library_init ()) { r_socket_free (s); return NULL; @@ -287,7 +287,8 @@ R_API int r_socket_port_by_name(const char *name) { R_API int r_socket_listen (RSocket *s, const char *port, const char *certfile) { int optval = 1; struct linger linger = { 0 }; - + if (r_sandbox_enable (0)) + return R_FALSE; #if __WINDOWS__ WSADATA wsadata; if (WSAStartup (MAKEWORD (1, 1), &wsadata) == SOCKET_ERROR) {