Text   |  XML   |  ReML   |   Visible Warnings:

Null Pointer Dereference  at file-dotlock.c:192

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

dotlock_create

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib/file-dotlock.c)expand/collapse
Show more  
 458  dotlock_create(struct dotlock *dotlock, enum dotlock_create_flags flags,
 459                 bool write_pid, const char **lock_path_r)
 460  {
 461          const struct dotlock_settings *set = &dotlock->settings;
 462          const char *lock_path;
 463          struct lock_info lock_info;
 464          struct stat st;
 465          unsigned int stale_notify_threshold;
 466          unsigned int change_secs, wait_left;
 467          time_t now, max_wait_time, last_notify;
 468          time_t prev_last_change = 0, prev_wait_update = 0;
 469          string_t *tmp_path;
 470          int ret;
 471          bool do_wait;
 472   
 473          now = time(NULL);
 474   
 475          lock_path = *lock_path_r =
 476[+]                 t_strconcat(dotlock->path, set->lock_suffix, NULL);
 477          stale_notify_threshold = set->stale_timeout / 2;
 478          max_wait_time = (flags & DOTLOCK_CREATE_FLAG_NONBLOCK) != 0 ? 0 :
 479                  now + set->timeout;
 480          tmp_path = t_str_new(256);
 481   
 482          memset(&lock_info, 0, sizeof(lock_info));
 483          lock_info.path = dotlock->path;
 484          lock_info.set = set;
 485          lock_info.lock_path = lock_path;
 486          lock_info.fd = -1;
 487          lock_info.use_io_notify = set->use_io_notify;
 488   
 489          last_notify = 0; do_wait = FALSE;
 490   
 491          do {
 492                  if (do_wait) {
 493                          if (prev_last_change != lock_info.last_change) {
 494                                  /* dotlock changed since last check,
 495                                     reset the wait time */
 496                                  lock_info.wait_usecs = LOCK_RANDOM_USLEEP_TIME;
 497                                  prev_last_change = lock_info.last_change;
 498                                  prev_wait_update = now;
 499                          } else if (prev_wait_update != now &&
 500                                     lock_info.wait_usecs < LOCK_MAX_WAIT_USECS) {
 501                                  /* we've been waiting for a while now, increase 
 502                                     the wait time to avoid wasting CPU */
 503                                  prev_wait_update = now;
 504                                  lock_info.wait_usecs += lock_info.wait_usecs/2;
 505                          }
 506                          dotlock_wait(&lock_info);
 507                          do_wait = FALSE;
 508                  }
 509   
 510[+]                 ret = check_lock(now, &lock_info);
expand/collapse

check_lock

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib/file-dotlock.c)expand/collapse
Show more  
 206  static int check_lock(time_t now, struct lock_info *lock_info)
 207  {
 208          time_t stale_timeout = lock_info->set->stale_timeout;
 209          pid_t pid = -1;
 210          bool changed;
 211          int ret;
 212   
 213[+]         if ((ret = update_lock_info(now, lock_info, &changed)) != 0)
 214                  return ret;
 215          if (changed || !lock_info->pid_read) {
 216                  /* either our first check or someone else got the lock file.
 217                     if the dotlock was created only a couple of seconds ago,
 218                     don't bother to read its PID. */
 219                  if (lock_info->lock_info.mtime >= now - STALE_PID_CHECK_SECS)
 220                          lock_info->pid_read = FALSE;
 221                  else {
 222                          pid = read_local_pid(lock_info->lock_path);
 223                          lock_info->pid_read = TRUE;
 224                  }
 225                  lock_info->have_pid = pid != -1;
 226          } else if (!lock_info->have_pid) {
 227                  /* no pid checking */
 228          } else {
 229                  if (lock_info->last_pid_check == now) {
 230                          /* we just checked the pid */
 231                          return 0;
 232                  }
 233   
 234                  /* re-read the pid. even if all times and inodes are the same,
 235                     the PID in the file might have changed if lock files were 
 236                     rapidly being recreated. */
 237                  pid = read_local_pid(lock_info->lock_path);
 238                  lock_info->have_pid = pid != -1;
 239          }
 240   
 241          if (lock_info->have_pid) {
 242                  /* we've local PID. Check if it exists. */
 243                  if (kill(pid, 0) == 0 || errno != ESRCH) {
 244                          if (pid != getpid()) {
 245                                  /* process exists, don't override */
 246                                  return 0;
 247                          }
 248                          /* it's us. either we're locking it again, or it's a 
 249                             stale lock file with same pid than us. either way,
 250                             recreate it.. */
 251                  }
 252   
 253                  /* doesn't exist - now check again if the dotlock was just
 254                     deleted or replaced */
 255                  if ((ret = update_lock_info(now, lock_info, &changed)) != 0)
 256                          return ret;
 257   
 258                  if (!changed) {
 259                          /* still there, go ahead and override it */
 260                          return dotlock_override(lock_info);
 261                  }
 262                  return 1;
 263          }
 264   
 265          if (stale_timeout == 0) {
 266                  /* no change checking */
 267                  return 0;
 268          }
 269   
 270          if (now > lock_info->last_change + stale_timeout) {
 271                  struct stat st;
 272   
 273                  /* possibly stale lock file. check also the timestamp of the
 274                     file we're protecting. */
 275                  if (lock_info->set->nfs_flush) {
 276                          nfs_flush_file_handle_cache(lock_info->path);
 277                          nfs_flush_attr_cache_maybe_locked(lock_info->path);
 278                  }
 279                  if (nfs_safe_stat(lock_info->path, &st) < 0) {
 280                          if (errno == ENOENT) {
 281                                  /* file doesn't exist. treat it as if
 282                                     it hasn't changed */
 283                          } else {
 284                                  i_error("stat(%s) failed: %m", lock_info->path);
 285                                  return -1;
 286                          }
 287                  } else {
 288                          (void)update_change_info(&st, &lock_info->file_info,
 289                                                   &lock_info->last_change, now,
 290                                                   !lock_info->set->nfs_flush);
 291                  }
 292          }
 293   
 294          if (now > lock_info->last_change + stale_timeout) {
 295                  /* no changes for a while, assume stale lock */
 296[+]                 return dotlock_override(lock_info);
expand/collapse

dotlock_override

(/home/sate/Testcases/c/cve/dovecot-1.2.0/src/lib/file-dotlock.c)expand/collapse
Show more  
 190  static int dotlock_override(struct lock_info *lock_info)
 191  {
 192          if (unlink(lock_info->lock_path) < 0 && errno != ENOENT) {
Show more  
Show more  
Show more  




Change Warning 7079.24945 : Null Pointer Dereference

Priority:
State:
Finding:
Owner:
Note: