vac: fix segfault on DMSYMLINK or DMDEVICE

Fix segfault when the first archived file is DMSYMLINK or DMDEVICE.
Reinitialize the buffer to zero before calling readlink.

R=rsc
CC=plan9port.codebot
http://codereview.appspot.com/5500097
This commit is contained in:
David du Colombier 2012-01-16 17:06:41 -05:00 committed by Russ Cox
parent 258cfab2fe
commit 68e24566b6

View file

@ -501,12 +501,17 @@ vac(VacFile *fp, VacFile *diffp, char *name, Dir *d)
if(vacfilesetdir(f, &vd) < 0)
warn("vacfilesetdir %s: %r", name);
bsize = fs->bsize;
if(buf == nil)
buf = vtmallocz(bsize);
#ifdef PLAN9PORT
if(d->mode&(DMSOCKET|DMNAMEDPIPE)){
/* don't write anything */
}
else if(d->mode&DMSYMLINK){
memset(buf, 0, sizeof buf);
n = readlink(name, buf, sizeof buf);
if(n > 0 && vacfilewrite(f, buf, n, 0) < 0){
warn("venti write %s: %r", name);
@ -539,9 +544,6 @@ vac(VacFile *fp, VacFile *diffp, char *name, Dir *d)
}
}else{
off = 0;
bsize = fs->bsize;
if(buf == nil)
buf = vtmallocz(bsize);
if(fdiff){
/*
* Copy fdiff's contents into f by moving the score.