Subject: pkg_add bugs
To: None <tech-pkg@netbsd.org>
From: Simon J. Gerraty <sjg@quick.com.au>
List: tech-pkg
Date: 06/17/2000 00:38:33
The diffs below fix a couple of bugs in pkg_add.
Firstly exit(1) is much safer than returning an error count from
main().
Second, extract_plist() can bail part way through - if it cannot back
up a file to be replaced, yet the calling function has no way of
knowing and continues as though nothing is wrong. The results can be
quite nasty.
Any reason not to commit these?
--sjg
Index: add/add.h
===================================================================
RCS file: /cvsroot/basesrc/usr.sbin/pkg_install/add/add.h,v
retrieving revision 1.4
diff -u -p -r1.4 add.h
--- add.h 1999/08/24 00:48:37 1.4
+++ add.h 2000/06/16 14:30:39
@@ -42,7 +42,7 @@ extern char FirstPen[];
extern add_mode_t AddMode;
int make_hierarchy(char *);
-void extract_plist(char *, package_t *);
+int extract_plist(char *, package_t *);
void apply_perms(char *, char *);
#endif /* _INST_ADD_H_INCLUDE */
Index: add/extract.c
===================================================================
RCS file: /cvsroot/basesrc/usr.sbin/pkg_install/add/extract.c,v
retrieving revision 1.20
diff -u -p -r1.20 extract.c
--- extract.c 1999/08/24 00:48:38 1.20
+++ extract.c 2000/06/16 14:30:40
@@ -86,7 +86,7 @@ rollback(char *name, char *home, plist_t
}
}
-void
+int
extract_plist(char *home, package_t *pkg)
{
plist_t *p = pkg->head;
@@ -162,7 +162,7 @@ extract_plist(char *home, package_t *pkg
"unable to back up %s to %s, aborting pkg_add",
try, pf);
rollback(PkgName, home, pkg->head, p);
- return;
+ return 0;
}
}
}
@@ -311,4 +311,5 @@ extract_plist(char *home, package_t *pkg
}
PUSHOUT(Directory);
pkgdb_close();
+ return 1;
}
Index: add/main.c
===================================================================
RCS file: /cvsroot/basesrc/usr.sbin/pkg_install/add/main.c,v
retrieving revision 1.14
diff -u -p -r1.14 main.c
--- main.c 2000/01/19 23:28:28 1.14
+++ main.c 2000/06/16 14:30:40
@@ -197,7 +197,7 @@ main(int argc, char **argv)
if ((error = pkg_perform(&pkgs)) != 0) {
if (Verbose)
warnx("%d package addition(s) failed", error);
- return error;
- } else
- return 0;
+ exit(1);
+ }
+ exit(0);
}
Index: add/perform.c
===================================================================
RCS file: /cvsroot/basesrc/usr.sbin/pkg_install/add/perform.c,v
retrieving revision 1.51
diff -u -p -r1.51 perform.c
--- perform.c 2000/05/16 15:59:16 1.51
+++ perform.c 2000/06/16 14:30:43
@@ -548,7 +548,10 @@ pkg_do(char *pkg)
/* Now finally extract the entire show if we're not going direct */
if (!inPlace && !Fake)
- extract_plist(".", &Plist);
+ if (!extract_plist(".", &Plist)) {
+ code = 1;
+ goto fail;
+ }
if (!Fake && fexists(MTREE_FNAME)) {
if (Verbose)