# HG changeset patch # User Matt Johnston # Date 1643598778 -28800 # Node ID adfcdfb161a4831f2797c75049d192afd4054f81 # Parent d940f8007a453de3a5f6d1b0befd7cb4f8c04d1d Fix missing NULL terminator for re-exec Also fixes fallback, sockets were not kept open diff -r d940f8007a45 -r adfcdfb161a4 svr-main.c --- a/svr-main.c Sun Jan 30 13:46:52 2022 +0800 +++ b/svr-main.c Mon Jan 31 11:12:58 2022 +0800 @@ -339,20 +339,25 @@ if (execfd >= 0) { #if DROPBEAR_DO_REEXEC /* Add "-2" to the args and re-execute ourself */ - char **new_argv = m_malloc(sizeof(char*) * (argc+1)); + char **new_argv = m_malloc(sizeof(char*) * (argc+2)); memcpy(new_argv, argv, sizeof(char*) * argc); new_argv[argc] = "-2"; + new_argv[argc+1] = NULL; if ((dup2(childsock, STDIN_FILENO) < 0)) { dropbear_exit("dup2 failed: %s", strerror(errno)); } - m_close(childsock); + if (fcntl(childsock, F_SETFD, FD_CLOEXEC) < 0) { + TRACE(("cloexec for childsock %d failed: %s", childsock, strerror(errno))) + } /* Re-execute ourself */ fexecve(execfd, new_argv, environ); /* Not reached on success */ - /* Fall back on plain fork otherwise */ - TRACE(("fexecve failed, disabling re-exec: %s", strerror(errno))) + /* Fall back on plain fork otherwise. + * To be removed in future once re-exec has been well tested */ + dropbear_log(LOG_WARNING, "fexecve failed, disabling re-exec: %s", strerror(errno)); + m_close(STDIN_FILENO); m_free(new_argv); #endif /* DROPBEAR_DO_REEXEC */ }