Text   |  XML   |  ReML   |   Visible Warnings:

Buffer Overrun  at var-expand.c:322

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

mail_process_exec

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/master/mail-process.c)expand/collapse
Show more  
 445  void mail_process_exec(const char *protocol, const char **args)
 446  {
 447          struct server_settings *server = settings_root;
 448          const struct var_expand_table *var_expand_table;
 449          struct settings *set;
 450          const char *executable;
 451   
 452          if (strcmp(protocol, "ext") == 0) {
 453                  /* external binary. section contains path for it. */
 454                  if (*args == NULL)
 455                          i_fatal("External binary parameter not given");
 456                  set = server->defaults;
 457                  executable = *args;
 458          } else {
 459                  const char *section = *args;
 460   
 461                  if (section != NULL) {
 462                          for (; server != NULL; server = server->next) {
 463                                  if (strcmp(server->name, section) == 0)
 464                                          break;
 465                          }
 466                          if (server == NULL)
 467                                  i_fatal("Section not found: '%s'", section);
 468                  }
 469   
 470                  if (strcmp(protocol, "imap") == 0)
 471                          set = server->imap;
 472                  else if (strcmp(protocol, "pop3") == 0)
 473                          set = server->pop3;
 474                  else 
 475                          i_fatal("Unknown protocol: '%s'", protocol);
 476                  executable = set->mail_executable;
 477                  args = NULL;
 478          }
 479   
 480          var_expand_table =
 481                  get_var_expand_table(protocol, getenv("USER"), getenv("HOME"),
 482                                       getenv("TCPLOCALIP"),
 483                                       getenv("TCPREMOTEIP"),
 484                                       getpid(), geteuid());
 485   
 486          /* set up logging */
 487          env_put(t_strconcat("LOG_TIMESTAMP=", set->log_timestamp, NULL));
 488          if (*set->log_path == '\0')
 489                  env_put("USE_SYSLOG=1");
 490          else 
 491                  env_put(t_strconcat("LOGFILE=", set->log_path, NULL));
 492          if (*set->info_log_path != '\0')
 493                  env_put(t_strconcat("INFOLOGFILE=", set->info_log_path, NULL));
 494          if (*set->mail_log_prefix != '\0') {
 495                  string_t *str = t_str_new(256);
 496   
 497                  str_append(str, "LOG_PREFIX=");
 498                  var_expand(str, set->mail_log_prefix, var_expand_table);
 499                  env_put(str_c(str));
 500          }
 501   
 502          mail_process_set_environment(set, getenv("MAIL"), var_expand_table,
 503[+]                                      TRUE);
expand/collapse

mail_process_set_environment

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/master/mail-process.c)expand/collapse
Show more  
 298  mail_process_set_environment(struct settings *set, const char *mail,
 299                               const struct var_expand_table *var_expand_table,
 300                               bool exec_mail)
 301  {
 302          const char *const *envs;
 303          string_t *str;
 304          unsigned int i, count;
 305   
 306          env_put(t_strconcat("BASE_DIR=", set->base_dir, NULL));
 307          env_put(t_strconcat("MAIL_CACHE_FIELDS=",
 308                              set->mail_cache_fields, NULL));
 309          env_put(t_strconcat("MAIL_NEVER_CACHE_FIELDS=",
 310                              set->mail_never_cache_fields, NULL));
 311          env_put(t_strdup_printf("MAIL_CACHE_MIN_MAIL_COUNT=%u",
 312                                  set->mail_cache_min_mail_count));
 313          env_put(t_strdup_printf("MAILBOX_IDLE_CHECK_INTERVAL=%u",
 314                                  set->mailbox_idle_check_interval));
 315          env_put(t_strdup_printf("MAIL_MAX_KEYWORD_LENGTH=%u",
 316                                  set->mail_max_keyword_length));
 317   
 318          if (set->protocol == MAIL_PROTOCOL_IMAP) {
 319                  env_put(t_strdup_printf("IMAP_MAX_LINE_LENGTH=%u",
 320                                          set->imap_max_line_length));
 321                  if (*set->imap_capability != '\0') {
 322                          env_put(t_strconcat("IMAP_CAPABILITY=",
 323                                              set->imap_capability, NULL));
 324                  }
 325                  env_put(t_strconcat("IMAP_CLIENT_WORKAROUNDS=",
 326                                      set->imap_client_workarounds, NULL));
 327                  env_put(t_strconcat("IMAP_LOGOUT_FORMAT=",
 328                                      set->imap_logout_format, NULL));
 329                  env_put(t_strconcat("IMAP_ID_SEND=", set->imap_id_send, NULL));
 330                  env_put(t_strconcat("IMAP_ID_LOG=", set->imap_id_log, NULL));
 331                  env_put(t_strdup_printf("IMAP_IDLE_NOTIFY_INTERVAL=%u",
 332                                          set->imap_idle_notify_interval));
 333          }
 334          if (set->protocol == MAIL_PROTOCOL_POP3) {
 335                  env_put(t_strconcat("POP3_CLIENT_WORKAROUNDS=",
 336                                      set->pop3_client_workarounds, NULL));
 337                  env_put(t_strconcat("POP3_LOGOUT_FORMAT=",
 338                                      set->pop3_logout_format, NULL));
 339                  if (set->pop3_no_flag_updates)
 340                          env_put("POP3_NO_FLAG_UPDATES=1");
 341                  if (set->pop3_reuse_xuidl)
 342                          env_put("POP3_REUSE_XUIDL=1");
 343                  if (set->pop3_enable_last)
 344                          env_put("POP3_ENABLE_LAST=1");
 345                  if (set->pop3_lock_session)
 346                          env_put("POP3_LOCK_SESSION=1");
 347          }
 348   
 349          /* We care about POP3 UIDL format in all process types */
 350          env_put(t_strconcat("POP3_UIDL_FORMAT=", set->pop3_uidl_format, NULL));
 351   
 352          if (set->mail_save_crlf)
 353                  env_put("MAIL_SAVE_CRLF=1");
 354          if (set->mmap_disable)
 355                  env_put("MMAP_DISABLE=1");
 356          if (set->dotlock_use_excl)
 357                  env_put("DOTLOCK_USE_EXCL=1");
 358          if (set->fsync_disable)
 359                  env_put("FSYNC_DISABLE=1");
 360          if (set->mail_nfs_storage)
 361                  env_put("MAIL_NFS_STORAGE=1");
 362          if (set->mail_nfs_index)
 363                  env_put("MAIL_NFS_INDEX=1");
 364          if (set->mailbox_list_index_disable)
 365                  env_put("MAILBOX_LIST_INDEX_DISABLE=1");
 366          if (set->maildir_stat_dirs)
 367                  env_put("MAILDIR_STAT_DIRS=1");
 368          if (set->maildir_copy_with_hardlinks)
 369                  env_put("MAILDIR_COPY_WITH_HARDLINKS=1");
 370          if (set->maildir_copy_preserve_filename)
 371                  env_put("MAILDIR_COPY_PRESERVE_FILENAME=1");
 372          if (set->maildir_very_dirty_syncs)
 373                  env_put("MAILDIR_VERY_DIRTY_SYNCS=1");
 374          if (set->mail_debug)
 375                  env_put("DEBUG=1");
 376          if (set->mail_full_filesystem_access)
 377                  env_put("FULL_FILESYSTEM_ACCESS=1");
 378          if (set->mbox_dirty_syncs)
 379                  env_put("MBOX_DIRTY_SYNCS=1");
 380          if (set->mbox_very_dirty_syncs)
 381                  env_put("MBOX_VERY_DIRTY_SYNCS=1");
 382          if (set->mbox_lazy_writes)
 383                  env_put("MBOX_LAZY_WRITES=1");
 384          /* when we're not certain that the log fd points to the master
 385             process's log pipe (dump-capability, --exec-mail), don't let 
 386             the imap process listen for stderr since it might break 
 387             (e.g. epoll_ctl() gives EPERM). */
 388          if (set->shutdown_clients && !exec_mail)
 389                  env_put("STDERR_CLOSE_SHUTDOWN=1");
 390          (void)umask(0077);
 391   
 392          env_put(t_strconcat("LOCK_METHOD=", set->lock_method, NULL));
 393          env_put(t_strconcat("MBOX_READ_LOCKS=", set->mbox_read_locks, NULL));
 394          env_put(t_strconcat("MBOX_WRITE_LOCKS=", set->mbox_write_locks, NULL));
 395          env_put(t_strdup_printf("MBOX_LOCK_TIMEOUT=%u",
 396                                  set->mbox_lock_timeout));
 397          env_put(t_strdup_printf("MBOX_DOTLOCK_CHANGE_TIMEOUT=%u",
 398                                  set->mbox_dotlock_change_timeout));
 399          env_put(t_strdup_printf("MBOX_MIN_INDEX_SIZE=%u",
 400                                  set->mbox_min_index_size));
 401   
 402          env_put(t_strdup_printf("DBOX_ROTATE_SIZE=%u",
 403                                  set->dbox_rotate_size));
 404          env_put(t_strdup_printf("DBOX_ROTATE_MIN_SIZE=%u",
 405                                  set->dbox_rotate_min_size));
 406          env_put(t_strdup_printf("DBOX_ROTATE_DAYS=%u",
 407                                  set->dbox_rotate_days));
 408   
 409          if (*set->mail_plugins != '\0') {
 410                  env_put(t_strconcat("MAIL_PLUGIN_DIR=",
 411                                      set->mail_plugin_dir, NULL));
 412                  env_put(t_strconcat("MAIL_PLUGINS=", set->mail_plugins, NULL));
 413          }
 414   
 415          /* user given environment - may be malicious. virtual_user comes from 
 416             auth process, but don't trust that too much either. Some auth
 417             mechanism might allow leaving extra data there. */
 418          if ((mail == NULL || *mail == '\0') && *set->mail_location != '\0')
 419                  mail = expand_mail_env(set->mail_location, var_expand_table);
 420          env_put(t_strconcat("MAIL=", mail, NULL));
 421   
 422          if (set->server->namespaces != NULL) {
 423                  env_put_namespace(set->server->namespaces,
 424[+]                                   mail, var_expand_table);
expand/collapse

env_put_namespace

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/master/mail-process.c)expand/collapse
Show more  
 248  env_put_namespace(struct namespace_settings *ns, const char *default_location,
 249                    const struct var_expand_table *table)
 250  {
 251          const char *location;
 252          unsigned int i;
 253          string_t *str;
 254   
 255          if (default_location == NULL)
 256                  default_location = "";
 257   
 258          for (i = 1; ns != NULL; i++, ns = ns->next) {
 259                  location = *ns->location != '\0' ? ns->location :
 260                          default_location;
 261[+]                 location = expand_mail_env(location, table);
expand/collapse

expand_mail_env

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/master/mail-process.c)expand/collapse
Show more  
 218  static const char *
 219  expand_mail_env(const char *env, const struct var_expand_table *table)
 220  {
 221          string_t *str;
 222          const char *p;
 223   
 224          str = t_str_new(256);
 225   
 226          /* it's either type:data or just data */
 227          p = strchr(env, ':');
 228          if (p != NULL) {
 229                  while (env != p) {
 230                          str_append_c(str, *env);
 231                          env++;
 232                  }
 233   
 234                  str_append_c(str, *env++);
 235          }
 236   
 237[+]         if (has_missing_used_home(env, table)) {
expand/collapse

has_missing_used_home

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/master/mail-process.c)expand/collapse
Show more  
 210  has_missing_used_home(const char *str, const struct var_expand_table *table)
 211  {
 212          i_assert(table[VAR_EXPAND_HOME_IDX].key == 'h');
 213   
 214          return table[VAR_EXPAND_HOME_IDX].value == NULL &&
 215[+]                 var_has_key(str, 'h', "home");
expand/collapse

var_has_key

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib/var-expand.c)expand/collapse
Show more  
 307  bool var_has_key(const char *str, char key, const char *long_key)
 308  {
 309          const char *end;
 310          char c;
 311   
 312          for (; *str != '\0'; str++) {
 313                  if (*str == '%' && str[1] != '\0') {
 314                          str++;
 315                          c = var_get_key(str);
 316                          if (c == key)
 317                                  return TRUE;
 318   
 319                          if (c == '{' && long_key != NULL &&
 320                              (str = strchr(str, '{')) != NULL &&
 321                              (end = strchr(++str, '}')) != NULL) {
 322                                  if (strncmp(str, long_key, end-str) == 0 &&
Show more  
Show more  
Show more  
Show more  
Show more  
Show more  




Change Warning 7795.24924 : Buffer Overrun

Priority:
State:
Finding:
Owner:
Note: