FelipeMdeO commented on code in PR #3532:
URL: https://github.com/apache/nuttx-apps/pull/3532#discussion_r3447662613


##########
netutils/dropbear/dropbear_main.c:
##########
@@ -0,0 +1,305 @@
+/****************************************************************************
+ * apps/netutils/dropbear/dropbear_main.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <sys/socket.h>
+#include <setjmp.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "includes.h"
+#include "algo.h"
+#include "crypto_desc.h"
+#define dropbear_main dropbear_multi_entry
+#include "dbutil.h"
+#undef dropbear_main
+#include "dbrandom.h"
+#include "netio.h"
+#include "runopts.h"
+#include "session.h"
+#include "ssh.h"
+#include "nuttx_hostkey.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define DROPBEAR_PORT_STRING_HELPER(n) #n
+#define DROPBEAR_PORT_STRING(n) DROPBEAR_PORT_STRING_HELPER(n)
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+typedef void (*dropbear_exit_handler_t)(int exitcode, FAR const char *format,
+                                        va_list param) ATTRIB_NORETURN;
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static jmp_buf g_session_exit_jmp;
+static int g_session_exitcode;
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static void dropbear_session_exit(int exitcode, FAR const char *format,
+                                  va_list param) noreturn_function;
+static void dropbear_session_exit(int exitcode, FAR const char *format,
+                                  va_list param)
+{
+  char exitmsg[150];
+  char fullmsg[300];
+  char fromaddr[60];
+  int signal_pipe[2];
+
+  vsnprintf(exitmsg, sizeof(exitmsg), format, param);
+
+  fromaddr[0] = '\0';
+
+  if (svr_ses.addrstring != NULL)
+    {
+      snprintf(fromaddr, sizeof(fromaddr), " from <%s>", svr_ses.addrstring);
+    }
+
+  if (!ses.init_done)
+    {
+      snprintf(fullmsg, sizeof(fullmsg), "Early exit%s: %s", fromaddr,
+               exitmsg);
+    }
+  else if (ses.authstate.authdone)
+    {
+      snprintf(fullmsg, sizeof(fullmsg), "Exit (%s)%s: %s",
+               ses.authstate.pw_name, fromaddr, exitmsg);
+    }
+  else if (ses.authstate.pw_name != NULL)
+    {
+      snprintf(fullmsg, sizeof(fullmsg),
+               "Exit before auth%s: (user '%s', %u fails): %s",
+               fromaddr, ses.authstate.pw_name, ses.authstate.failcount,
+               exitmsg);
+    }
+  else
+    {
+      snprintf(fullmsg, sizeof(fullmsg), "Exit before auth%s: %s", fromaddr,
+               exitmsg);
+    }
+
+  dropbear_log(LOG_INFO, "%s", fullmsg);
+
+  signal_pipe[0] = ses.signal_pipe[0];
+  signal_pipe[1] = ses.signal_pipe[1];
+  session_cleanup();

Review Comment:
   Hello mkj, nice catch. 
   This type of problem is critical.
   
   NuttX has "tools" to handle memory properly but I will follow your 
suggestion to use DROPBEAR_TRACKING_MALLOC because it is more simple to apply.
   
   You can check fix in commit she: 7f37a59d8fef9648fadf8418ea36e76ae047454f



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to