Mercurial > dropbear
comparison svr-main.c @ 1866:adfcdfb161a4
Fix missing NULL terminator for re-exec
Also fixes fallback, sockets were not kept open
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Mon, 31 Jan 2022 11:12:58 +0800 |
parents | 2b3a8026a6ce |
children | 0dcc5b0d93fa |
comparison
equal
deleted
inserted
replaced
1865:d940f8007a45 | 1866:adfcdfb161a4 |
---|---|
337 m_close(childpipe[0]); | 337 m_close(childpipe[0]); |
338 | 338 |
339 if (execfd >= 0) { | 339 if (execfd >= 0) { |
340 #if DROPBEAR_DO_REEXEC | 340 #if DROPBEAR_DO_REEXEC |
341 /* Add "-2" to the args and re-execute ourself */ | 341 /* Add "-2" to the args and re-execute ourself */ |
342 char **new_argv = m_malloc(sizeof(char*) * (argc+1)); | 342 char **new_argv = m_malloc(sizeof(char*) * (argc+2)); |
343 memcpy(new_argv, argv, sizeof(char*) * argc); | 343 memcpy(new_argv, argv, sizeof(char*) * argc); |
344 new_argv[argc] = "-2"; | 344 new_argv[argc] = "-2"; |
345 new_argv[argc+1] = NULL; | |
345 | 346 |
346 if ((dup2(childsock, STDIN_FILENO) < 0)) { | 347 if ((dup2(childsock, STDIN_FILENO) < 0)) { |
347 dropbear_exit("dup2 failed: %s", strerror(errno)); | 348 dropbear_exit("dup2 failed: %s", strerror(errno)); |
348 } | 349 } |
349 m_close(childsock); | 350 if (fcntl(childsock, F_SETFD, FD_CLOEXEC) < 0) { |
351 TRACE(("cloexec for childsock %d failed: %s", childsock, strerror(errno))) | |
352 } | |
350 /* Re-execute ourself */ | 353 /* Re-execute ourself */ |
351 fexecve(execfd, new_argv, environ); | 354 fexecve(execfd, new_argv, environ); |
352 /* Not reached on success */ | 355 /* Not reached on success */ |
353 | 356 |
354 /* Fall back on plain fork otherwise */ | 357 /* Fall back on plain fork otherwise. |
355 TRACE(("fexecve failed, disabling re-exec: %s", strerror(errno))) | 358 * To be removed in future once re-exec has been well tested */ |
359 dropbear_log(LOG_WARNING, "fexecve failed, disabling re-exec: %s", strerror(errno)); | |
360 m_close(STDIN_FILENO); | |
356 m_free(new_argv); | 361 m_free(new_argv); |
357 #endif /* DROPBEAR_DO_REEXEC */ | 362 #endif /* DROPBEAR_DO_REEXEC */ |
358 } | 363 } |
359 | 364 |
360 /* start the session */ | 365 /* start the session */ |