[PATCH] audit handling of waitpid() status codes
Martin Pool
mbp at samba.org
Thu Jan 9 06:13:00 GMT 2003
I found a data-corruption bug in ccache a few weeks ago relating to
incorrect handling of wait() status codes, so I thought I would do a
quick check for similar things in Samba.
A patch is included:
- several cases where child process failure is not detected
- one inverted boolean
- better messages when child processes crash
- one fixme I easily see how to handle
- one typo
I think the external behaviour is otherwise the same.
Could somebody please review this?
--
Martin
cvs server: Diffing .
cvs server: Diffing aparser
cvs server: Diffing aparser/templates
cvs server: Diffing auth
cvs server: Diffing bin
cvs server: Diffing client
Index: client/smbmount.c
===================================================================
RCS file: /data/cvs/samba/source/client/smbmount.c,v
retrieving revision 1.57
diff -u -r1.57 smbmount.c
--- client/smbmount.c 13 Nov 2002 02:21:55 -0000 1.57
+++ client/smbmount.c 9 Jan 2003 06:09:08 -0000
@@ -79,7 +79,11 @@
break;
}
/* If we get here - the child exited with some error status */
- exit(status);
+ if (WIFSIGNALLED(status)) {
+ exit(128 + WTERMSIG(status));
+ } else {
+ exit(WEXITSTATUS(status));
+ }
}
signal( SIGTERM, SIG_DFL );
@@ -499,6 +503,9 @@
if (WIFEXITED(status) && WEXITSTATUS(status) != 0) {
fprintf(stderr,"smbmnt failed: %d\n", WEXITSTATUS(status));
/* FIXME: do some proper error handling */
+ exit(1);
+ } else if (WIFSIGNALLED(status)) {
+ fprintf(stderr, "smbmnt killed by signal %d\n", WTERMSIG(status));
exit(1);
}
cvs server: Diffing codepages
cvs server: Diffing groupdb
cvs server: Diffing include
cvs server: Diffing intl
cvs server: Diffing lib
Index: lib/smbrun.c
===================================================================
RCS file: /data/cvs/samba/source/lib/smbrun.c,v
retrieving revision 1.20
diff -u -r1.20 smbrun.c
--- lib/smbrun.c 28 Jul 2002 02:20:15 -0000 1.20
+++ lib/smbrun.c 9 Jan 2003 06:09:08 -0000
@@ -130,6 +130,11 @@
return WEXITSTATUS(status);
}
#endif
+#if defined(WIFSIGNALLED) && defined(WTERMSIG)
+ if (WIFSIGNALLED(status)) {
+ return 128 + WTERMSIG(status);
+ }
+#endif
return status;
}
Index: lib/util_file.c
===================================================================
RCS file: /data/cvs/samba/source/lib/util_file.c,v
retrieving revision 1.36
diff -u -r1.36 util_file.c
--- lib/util_file.c 28 Jun 2002 03:19:20 -0000 1.36
+++ lib/util_file.c 9 Jan 2003 06:09:08 -0000
@@ -362,7 +362,7 @@
while ((n = read(fd, buf, sizeof(buf))) > 0) {
tp = Realloc(p, total + n + 1);
if (!tp) {
- DEBUG(0,("file_pload: failed to exand buffer!\n"));
+ DEBUG(0,("file_pload: failed to expand buffer!\n"));
close(fd);
SAFE_FREE(p);
return NULL;
@@ -372,6 +372,8 @@
}
if (p) p[total] = 0;
+ /* FIXME: Perhaps ought to check that the command completed
+ * successfully; if not the data may be truncated. */
sys_pclose(fd);
if (size) *size = total;
cvs server: Diffing libads
cvs server: Diffing libsmb
cvs server: Diffing locking
cvs server: Diffing msdfs
cvs server: Diffing nmbd
cvs server: Diffing nsswitch
cvs server: Diffing pam_smbpass
cvs server: Diffing pam_smbpass/samples
cvs server: Diffing param
cvs server: Diffing passdb
cvs server: Diffing po
cvs server: Diffing popt
cvs server: Diffing printing
cvs server: Diffing profile
cvs server: Diffing python
cvs server: Diffing python/examples
cvs server: Diffing python/examples/spoolss
cvs server: Diffing python/examples/tdbpack
cvs server: Diffing python/samba
cvs server: Diffing registry
cvs server: Diffing rpc_client
cvs server: Diffing rpc_parse
cvs server: Diffing rpc_server
cvs server: Diffing rpcclient
cvs server: Diffing sam
cvs server: Diffing script
cvs server: Diffing smbd
Index: smbd/chgpasswd.c
===================================================================
RCS file: /data/cvs/samba/source/smbd/chgpasswd.c,v
retrieving revision 1.97
diff -u -r1.97 chgpasswd.c
--- smbd/chgpasswd.c 8 Jan 2003 07:02:18 -0000 1.97
+++ smbd/chgpasswd.c 9 Jan 2003 06:09:09 -0000
@@ -408,20 +408,20 @@
("We were waiting for the wrong process ID\n"));
return (False);
}
- if (WIFEXITED(wstat) == 0)
+ if (WIFEXITED(wstat))
{
DEBUG(3,
- ("The process exited while we were waiting\n"));
+ ("The process exited with code %d while we were waiting\n",
+ WEXITSTATUS(wstat)));
return (False);
}
- if (WEXITSTATUS(wstat) != 0)
+ else if (WIFSIGNALLED(wstat))
{
DEBUG(3,
- ("The status of the process exiting was %d\n",
- wstat));
+ ("The process was killed by signal %d while we were waiting\n",
+ WTERMSIG(wstat)));
return (False);
}
-
}
else
{
cvs server: Diffing smbwrapper
cvs server: Diffing tdb
Index: tdb/tdbtorture.c
===================================================================
RCS file: /data/cvs/samba/source/tdb/tdbtorture.c,v
retrieving revision 1.16
diff -u -r1.16 tdbtorture.c
--- tdb/tdbtorture.c 11 Dec 2001 08:31:58 -0000 1.16
+++ tdb/tdbtorture.c 9 Jan 2003 06:09:09 -0000
@@ -203,9 +203,14 @@
(int)pids[i+1]);
exit(1);
}
- if (WEXITSTATUS(status) != 0) {
+ if (WIFEXITED(status) && WEXITSTATUS(status) != 0) {
printf("child %d exited with status %d\n",
(int)pids[i+1], WEXITSTATUS(status));
+ exit(1);
+ }
+ else if (WIFSIGNALLED(status)) {
+ printf("child %d killed by signal %d\n",
+ (int)pids[i+1], WTERMSIG(status));
exit(1);
}
}
cvs server: Diffing tests
cvs server: Diffing torture
cvs server: Diffing ubiqx
cvs server: Diffing utils
cvs server: Diffing web
cvs server: Diffing wrepld
cvs server: Diffing .
cvs server: Diffing browserd
cvs server: Diffing lsarpcd
cvs server: Diffing mem_man
cvs server: Diffing modules
cvs server: Diffing msrpc
cvs server: Diffing netlogond
cvs server: Diffing pam_ntdom
cvs server: Diffing samrd
cvs server: Diffing spoolssd
cvs server: Diffing srvsvcd
cvs server: Diffing svcctld
cvs server: Diffing web
cvs server: Diffing web/po
cvs server: Diffing winregd
cvs server: Diffing wkssvcd
More information about the samba-technical
mailing list