From 3bda777c0839af6f6010d2677bb6fc7abbcce0c6 Mon Sep 17 00:00:00 2001 From: Kirk McKusick Date: Thu, 22 Sep 1983 15:29:40 -0800 Subject: [PATCH] check that chdir worked before trying to read directory (genji@topaz) SCCS-vsn: old/tar/tar.c 4.19 --- usr/src/old/tar/tar.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/usr/src/old/tar/tar.c b/usr/src/old/tar/tar.c index 548140871e..afe096c3e1 100644 --- a/usr/src/old/tar/tar.c +++ b/usr/src/old/tar/tar.c @@ -1,5 +1,5 @@ #ifndef lint -static char *sccsid = "@(#)tar.c 4.18 (Berkeley) %G%"; +static char *sccsid = "@(#)tar.c 4.19 (Berkeley) %G%"; #endif /* @@ -333,7 +333,10 @@ dorep(argv) cp2++; } putfile(*argv++, cp2, parent); - chdir(wdir); + if (chdir(wdir) < 0) { + fprintf(stderr, "cannot change back?: "); + perror(wdir); + } } putempty(); putempty(); @@ -457,11 +460,17 @@ putfile(longname, shortname, parent) writetape((char *)&dblock); } sprintf(newparent, "%s/%s", parent, shortname); - chdir(shortname); + if (chdir(shortname) < 0) { + perror(shortname); + return; + } if ((dirp = opendir(".")) == NULL) { fprintf(stderr, "tar: %s: directory read error\n", longname); - chdir(parent); + if (chdir(parent) < 0) { + fprintf(stderr, "cannot change back?: "); + perror(parent); + } return; } while ((dp = readdir(dirp)) != NULL && !term) { @@ -478,7 +487,10 @@ putfile(longname, shortname, parent) seekdir(dirp, i); } closedir(dirp); - chdir(parent); + if (chdir(parent) < 0) { + fprintf(stderr, "cannot change back?: "); + perror(parent); + } break; case S_IFLNK: -- 2.20.1