comparison cli-runopts.c @ 961:a4032b946355

Be a bit safer in case pw_name doesn't exist
author Matt Johnston <matt@ucc.asn.au>
date Wed, 06 Aug 2014 22:10:57 +0800
parents 1bf92da7a2a0
children 6fb4c010c448
comparison
equal deleted inserted replaced
960:9e7b0810a4a2 961:a4032b946355
681 struct passwd *pw = NULL; 681 struct passwd *pw = NULL;
682 682
683 uid = getuid(); 683 uid = getuid();
684 684
685 pw = getpwuid(uid); 685 pw = getpwuid(uid);
686 if (pw == NULL || pw->pw_name == NULL) { 686 if (pw && pw->pw_name != NULL) {
687 cli_opts.own_user = m_strdup(pw->pw_name);
688 } else {
687 dropbear_log(LOG_INFO, "Warning: failed to identify current user. Trying anyway."); 689 dropbear_log(LOG_INFO, "Warning: failed to identify current user. Trying anyway.");
688 } 690 cli_opts.own_user = m_strdup("unknown");
689 691 }
690 cli_opts.own_user = m_strdup(pw->pw_name); 692
691 } 693 }
692 694
693 #ifdef ENABLE_CLI_ANYTCPFWD 695 #ifdef ENABLE_CLI_ANYTCPFWD
694 /* Turn a "[listenaddr:]listenport:remoteaddr:remoteport" string into into a forwarding 696 /* Turn a "[listenaddr:]listenport:remoteaddr:remoteport" string into into a forwarding
695 * set, and add it to the forwarding list */ 697 * set, and add it to the forwarding list */