Saturday, August 26, 2017

Re: Query regarding exec in mandocdb.c

Hi George,

George Brown wrote on Thu, Aug 24, 2017 at 02:01:05PM +0100:

> In mandocdb.c it appears cmp(1) and rm(1) are executed in a child
> process. It seems that if the logic from these programs were duplicated
> the pledge in mandocdb.c could be further restricted and even not bother
> with forking.

Done as well, see the commit below.

Thanks again for the suggestion,
Ingo


Log Message:
-----------
Do not fork and exec cmp(1); instead, simply fstat(2), mmap(2), and
compare the files directly, allowing a much stricter pledge(2), at
very little cost: merely 15 additional lines of very simple code.
Suggested by George Brown <321 dot george at gmail dot com> on misc@.

Modified Files:
--------------
mandoc:
mandocdb.c

Revision Data
-------------
Index: mandocdb.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mandocdb.c,v
retrieving revision 1.254
retrieving revision 1.255
diff -Lmandocdb.c -Lmandocdb.c -u -p -r1.254 -r1.255
--- mandocdb.c
+++ mandocdb.c
@@ -19,8 +19,8 @@
#include "config.h"

#include <sys/types.h>
+#include <sys/mman.h>
#include <sys/stat.h>
-#include <sys/wait.h>

#include <assert.h>
#include <ctype.h>
@@ -319,7 +319,7 @@ mandocdb(int argc, char *argv[])
int ch, i;

#if HAVE_PLEDGE
- if (pledge("stdio rpath wpath cpath fattr flock proc exec", NULL) == -1) {
+ if (pledge("stdio rpath wpath cpath", NULL) == -1) {
warn("pledge");
return (int)MANDOCLEVEL_SYSERR;
}
@@ -440,15 +440,6 @@ mandocdb(int argc, char *argv[])
* The existing database is usable. Process
* all files specified on the command-line.
*/
-#if HAVE_PLEDGE
- if (!nodb) {
- if (pledge("stdio rpath wpath cpath fattr flock", NULL) == -1) {
- warn("pledge");
- exitcode = (int)MANDOCLEVEL_SYSERR;
- goto out;
- }
- }
-

No comments:

Post a Comment