0001-Fix-queue-file-seek-position-races-by-locking.patch

roe, 07/10/2009 10:24 AM

Download (2.07 KB)

View differences:

libexec/dma/dma.c
612 612
	const char *errmsg = "unknown bounce reason";
613 613
	struct timeval now;
614 614
	struct stat st;
615
	struct flock fl;
615 616

  
616 617
	syslog(LOG_INFO, "%s: mail from=<%s> to=<%s>",
617 618
	       it->queueid, it->sender, it->addr);
......
620 621
	syslog(LOG_INFO, "%s: trying delivery",
621 622
	       it->queueid);
622 623

  
624
	bzero(&fl, sizeof(fl));
625
	fl.l_type = F_WRLCK;
626
	fl.l_whence = SEEK_SET;
627
	if (fcntl(fileno(it->queuef), F_SETLKW, &fl) == -1) {
628
		syslog(LOG_ERR, "%s: failed to lock queue file: %m",
629
				it->queueid);
630
		goto bounce;
631
	}
632

  
623 633
	if (it->remote)
624 634
		error = deliver_remote(it, &errmsg);
625 635
	else
626 636
		error = deliver_local(it, &errmsg);
627 637

  
638
	bzero(&fl, sizeof(fl));
639
	fl.l_type = F_UNLCK;
640
	fl.l_whence = SEEK_SET;
641
	if (fcntl(fileno(it->queuef), F_SETLKW, &fl) == -1) {
642
		syslog(LOG_ERR, "%s: failed to unlock queue file: %m",
643
				it->queueid);
644
		/* let `error' decide whether we bounce or not */
645
	}
646

  
628 647
	switch (error) {
629 648
	case 0:
630 649
		unlink(it->queuefn);
631
-