Text   |  XML   |  ReML   |   Visible Warnings:

Buffer Overrun  at strfuncs.c:39

No properties have been set. | edit properties
Jump to warning location ↓ warning details...
Show Events | Options

main

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/deliver/deliver.c)expand/collapse
Show more  
 885  int main(int argc, char *argv[])
 886  {
 887          const char *config_path = DEFAULT_CONFIG_FILE;
 888          const char *mailbox = "INBOX";
 889          const char *auth_socket;
 890          const char *home, *destaddr, *user, *value, *errstr, *path, *orig_user;
 891          ARRAY_TYPE(const_string) extra_fields = ARRAY_INIT;
 892          struct mail_user *mail_user, *raw_mail_user;
 893          struct mail_namespace *raw_ns;
 894          struct mail_storage *storage;
 895          struct mailbox *box;
 896          struct raw_mailbox *raw_box;
 897          struct istream *input;
 898          struct mailbox_transaction_context *t;
 899          struct mailbox_header_lookup_ctx *headers_ctx;
 900          struct mail *mail;
 901          char cwd[PATH_MAX];
 902          uid_t process_euid;
 903          bool stderr_rejection = FALSE;
 904          bool keep_environment = FALSE;
 905          bool user_auth = FALSE;
 906          time_t mtime;
 907          int i, ret;
 908          pool_t userdb_pool = NULL;
 909          string_t *str;
 910          enum mail_error error;
 911   
 912          if (getuid() != geteuid() && geteuid() == 0) {
 913                  /* running setuid - don't allow this if deliver is 
 914                     executable by anyone */
 915                  struct stat st;
 916   
 917                  if (stat(argv[0], &st) < 0) {
 918                          fprintf(stderr, "stat(%s) failed: %s\n",
 919                                  argv[0], strerror(errno));
 920                          return EX_CONFIG;
 921                  } else if ((st.st_mode & 1) != 0) {
 922                          fprintf(stderr, "%s must not be both world-executable "
 923                                  "and setuid-root. This allows root exploits. "
 924                                  "See http://wiki.dovecot.org/LDA#multipleuids\n",
 925                                  argv[0]);
 926                          return EX_CONFIG;
 927                  }
 928          }
 929   
 930          i_set_failure_exit_callback(failure_exit_callback);
 931   
 932          lib_init();
 933          ioloop = io_loop_create();
 934   
 935          lib_signals_init();
 936          lib_signals_set_handler(SIGINT, TRUE, sig_die, NULL);
 937          lib_signals_set_handler(SIGTERM, TRUE, sig_die, NULL);
 938          lib_signals_ignore(SIGPIPE, TRUE);
 939          lib_signals_ignore(SIGALRM, FALSE);
 940  #ifdef SIGXFSZ 
 941          lib_signals_ignore(SIGXFSZ, TRUE);
 942  #endif
 943   
 944          deliver_set = i_new(struct deliver_settings, 1);
 945          deliver_set->mailbox_autocreate = TRUE;
 946   
 947          destaddr = user = path = NULL;
 948          for (i = 1; i < argc; i++) {
 949                  if (strcmp(argv[i], "-a") == 0) {
 950                          /* destination address */
 951                          i++;
 952                          if (i == argc)
 953                                  i_fatal_status(EX_USAGE, "Missing -a argument");
 954                          destaddr = argv[i];
 955                  } else if (strcmp(argv[i], "-d") == 0) {
 956                          /* destination user */
 957                          i++;
 958                          if (i == argc)
 959                                  i_fatal_status(EX_USAGE, "Missing -d argument");
 960                          user = argv[i];
 961                          user_auth = TRUE;
 962                  } else if (strcmp(argv[i], "-p") == 0) {
 963                          /* input path */
 964                          i++;
 965                          if (i == argc)
 966                                  i_fatal_status(EX_USAGE, "Missing -p argument");
 967                          path = argv[i];
 968                          if (*path != '/') {
 969                                  /* expand relative paths before we chdir */
 970                                  if (getcwd(cwd, sizeof(cwd)) == NULL)
 971                                          i_fatal("getcwd() failed: %m");
 972                                  path = t_strconcat(cwd, "/", path, NULL);
 973                          }
 974                  } else if (strcmp(argv[i], "-e") == 0) {
 975                          stderr_rejection = TRUE;
 976                  } else if (strcmp(argv[i], "-c") == 0) {
 977                          /* config file path */
 978                          i++;
 979                          if (i == argc) {
 980                                  i_fatal_status(EX_USAGE,
 981                                          "Missing config file path argument");
 982                          }
 983                          config_path = argv[i];
 984                  } else if (strcmp(argv[i], "-k") == 0) {
 985                          keep_environment = TRUE;
 986                  } else if (strcmp(argv[i], "-m") == 0) {
 987                          /* destination mailbox */
 988                          i++;
 989                          if (i == argc)
 990                                  i_fatal_status(EX_USAGE, "Missing -m argument");
 991                          /* Ignore -m "". This allows doing -m ${extension}
 992                             in Postfix to handle user+mailbox */
 993                          if (*argv[i] != '\0') {
 994                                  str = t_str_new(256);
 995                                  if (imap_utf8_to_utf7(argv[i], str) < 0) {
 996
1008
Show [ Lines 996 to 1008 omitted. ]
 1009                                  i_fatal_status(EX_USAGE, "Missing -f argument");
 1010                          explicit_envelope_sender =
 1011                                  i_strdup(address_sanitize(argv[i]));
 1012                  } else if (argv[i][0] != '\0') {
 1013                          print_help();
 1014                          i_fatal_status(EX_USAGE,
 1015                                         "Unknown argument: %s", argv[i]);
 1016                  }
 1017          }
 1018   
 1019          if (user == NULL)
 1020                  user = getenv("USER");
 1021          if (!keep_environment)
 1022                  deliver_env_clean(!user_auth);
 1023   
 1024          process_euid = geteuid();
 1025          if (user_auth)
 1026                  ;
 1027          else if (process_euid != 0) {
 1028                  /* we're non-root. get our username and possibly our home. */
 1029                  struct passwd *pw;
 1030   
 1031                  home = getenv("HOME");
 1032                  if (user != NULL && home != NULL) {
 1033                          /* no need for a pw lookup */
 1034                  } else if ((pw = getpwuid(process_euid)) != NULL) {
 1035                          user = t_strdup(pw->pw_name);
 1036                          if (home == NULL)
 1037                                  env_put(t_strconcat("HOME=", pw->pw_dir, NULL));
 1038                  } else if (user == NULL) {
 1039                          i_fatal_status(EX_USAGE,
 1040                                         "Couldn't lookup our username (uid=%s)",
 1041                                         dec2str(process_euid));
 1042                  }
 1043          } else {
 1044                  i_fatal_status(EX_USAGE,
 1045                          "destination user parameter (-d user) not given");
 1046          }
 1047   
 1048          T_BEGIN {
 1049                  config_file_init(config_path);
 1050          } T_END;
 1051          open_logfile(user);
 1052   
 1053          if (getenv("MAIL_DEBUG") != NULL)
 1054                  env_put("DEBUG=1");
 1055   
 1056          if (getenv("MAIL_PLUGINS") == NULL)
 1057                  modules = NULL;
 1058          else {
 1059                  const char *plugin_dir = getenv("MAIL_PLUGIN_DIR");
 1060                  const char *version;
 1061   
 1062                  if (plugin_dir == NULL)
 1063                          plugin_dir = MODULEDIR"/lda";
 1064   
 1065                  version = getenv("VERSION_IGNORE") != NULL ?
 1066                          NULL : PACKAGE_VERSION;
 1067                  modules = module_dir_load(plugin_dir, getenv("MAIL_PLUGINS"),
 1068                                            TRUE, version);
 1069          }
 1070   
 1071          if (user_auth) {
 1072                  auth_socket = getenv("AUTH_SOCKET_PATH");
 1073                  if (auth_socket == NULL) {
 1074                          const char *base_dir = getenv("BASE_DIR");
 1075                          if (base_dir == NULL)
 1076                                  base_dir = PKG_RUNDIR;
 1077                          auth_socket = t_strconcat(base_dir, "/auth-master",
 1078                                                    NULL);
 1079                  }
 1080   
 1081                  userdb_pool = pool_alloconly_create("userdb lookup replys", 512);
 1082
1091
Show [ Lines 1082 to 1091 omitted. ]
 1092                          if (getenv("DEBUG") != NULL)
 1093                                  i_info("userdb changed username to %s", user);
 1094                          i_set_failure_prefix(t_strdup_printf("deliver(%s): ",
 1095                                                               user));
 1096                  }
 1097                  /* if user was changed, it was allocated from userdb_pool 
 1098                     which we'll free soon. */
 1099                  user = t_strdup(user);
 1100          }
 1101   
 1102          expand_envs(user);
 1103          if (userdb_pool != NULL) {
 1104                  putenv_extra_fields(&extra_fields);
 1105                  pool_unref(&userdb_pool);
 1106          }
 1107   
 1108          /* Fix namespaces with empty locations */
 1109          for (i = 1;; i++) {
 1110                  value = getenv(t_strdup_printf("NAMESPACE_%u", i));
 1111                  if (value == NULL)
 1112                          break;
 1113   
 1114                  if (*value == '\0') {
 1115                          env_put(t_strdup_printf("NAMESPACE_%u=%s", i,
 1116[+][+]                                                 getenv("MAIL")));
expand/collapse

env_put

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib/env-util.c)expand/collapse
Show more  
 15  void env_put(const char *env)
 16  {
 17          if (env_pool == NULL) {
 18                  env_pool = pool_alloconly_create(MEMPOOL_GROWING"Environment",
 19                                                   2048);
 20          }
 21[+]         if (putenv(p_strdup(env_pool, env)) != 0)
expand/collapse

p_strdup

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib/strfuncs.c)expand/collapse
Show more  
 31  char *p_strdup(pool_t pool, const char *str)
 32  {
 33          void *mem;
 34          size_t len;
 35   
 36          if (str == NULL)
 37                  return NULL;
 38   
 39          for (len = 0; (str)[len] != '\0'; )
 40                  len++;
Show more  
Show more  
Show more  




Change Warning 8021.25624 : Buffer Overrun

Priority:
State:
Finding:
Owner:
Note: