shithub: riscv

Download patch

ref: 1a900513fb137143e1c1f8177975952bc404f5a9
parent: 5e59c57bb110403f83a41ad88415e108c6cb1f6a
author: cinap_lenrek <[email protected]>
date: Mon Dec 7 10:15:02 EST 2020

libndb: open internal file-descriptors with OCEXEC flag

--- a/sys/src/libndb/csgetval.c
+++ b/sys/src/libndb/csgetval.c
@@ -25,10 +25,10 @@
 		snprint(line, sizeof(line), "%s/cs", netroot);
 	else
 		strcpy(line, "/net/cs");
-	fd = open(line, ORDWR);
+	fd = open(line, ORDWR|OCEXEC);
 	if(fd < 0)
 		return nil;
-	seek(fd, 0, 0);
+
 	snprint(line, sizeof(line), "!%s=%s %s=*", attr, val, rattr);
 	if(write(fd, line, strlen(line)) < 0){
 		close(fd);
--- a/sys/src/libndb/csipinfo.c
+++ b/sys/src/libndb/csipinfo.c
@@ -23,10 +23,10 @@
 		snprint(line, sizeof(line), "%s/cs", netroot);
 	else
 		strcpy(line, "/net/cs");
-	fd = open(line, ORDWR);
+	fd = open(line, ORDWR|OCEXEC);
 	if(fd < 0)
-		return 0;
-	seek(fd, 0, 0);
+		return nil;
+
 	e = line + sizeof(line);
 	p = seprint(line, e, "!ipinfo %s=%s", attr, val);
 	for(i = 0; i < n; i++){
@@ -37,11 +37,11 @@
 	
 	if(write(fd, line, strlen(line)) < 0){
 		close(fd);
-		return 0;
+		return nil;
 	}
 	seek(fd, 0, 0);
 
-	first = last = 0;
+	first = last = nil;
 	for(;;){
 		n = read(fd, line, sizeof(line)-2);
 		if(n <= 0)
@@ -50,15 +50,15 @@
 		line[n+1] = 0;
 
 		t = _ndbparseline(line);
-		if(t == 0)
+		if(t == nil)
 			continue;
-		if(first)
+		if(first != nil)
 			last->entry = t;
 		else
 			first = t;
 		last = t;
 
-		while(last->entry)
+		while(last->entry != nil)
 			last = last->entry;
 	}
 	close(fd);
--- a/sys/src/libndb/dnsquery.c
+++ b/sys/src/libndb/dnsquery.c
@@ -29,7 +29,7 @@
 		net = "/net";
 
 	snprint(buf, sizeof(buf), "%s/dns", net);
-	if((fd = open(buf, ORDWR)) < 0)
+	if((fd = open(buf, ORDWR|OCEXEC)) < 0)
 		return nil;
 
 	/* zero out the error string */
@@ -84,7 +84,6 @@
 	int n;
 	Ndbtuple *t, *first, *last;
 
-	seek(fd, 0, 0);
 	snprint(buf, sizeof(buf), "!%s %s", dn, type);
 	if(write(fd, buf, strlen(buf)) < 0)
 		return nil;
--- a/sys/src/libndb/ndbhash.c
+++ b/sys/src/libndb/ndbhash.c
@@ -57,7 +57,7 @@
 
 	/* try opening the data base if it's closed */
 	if(db->mtime==0 && ndbreopen(db) < 0)
-		return 0;
+		return nil;
 
 	/* if the database has changed, throw out hash files and reopen db */
 	if((d = dirfstat(Bfildes(&db->b))) == nil || db->qid.path != d->qid.path
@@ -64,16 +64,16 @@
 	|| db->qid.vers != d->qid.vers){
 		if(ndbreopen(db) < 0){
 			free(d);
-			return 0;
+			return nil;
 		}
 	}
 	free(d);
 
 	if(db->nohash)
-		return 0;
+		return nil;
 
 	/* see if a hash file exists for this attribute */
-	for(hf = db->hf; hf; hf= hf->next){
+	for(hf = db->hf; hf != nil; hf= hf->next){
 		if(strcmp(hf->attr, attr) == 0)
 			return hf;
 	}
@@ -80,19 +80,19 @@
 
 	/* create a new one */
 	hf = (Ndbhf*)malloc(sizeof(Ndbhf));
-	if(hf == 0)
-		return 0;
+	if(hf == nil)
+		return nil;
 	memset(hf, 0, sizeof(Ndbhf));
 
 	/* compare it to the database file */
 	strncpy(hf->attr, attr, sizeof(hf->attr)-1);
 	sprint(buf, "%s.%s", db->file, hf->attr);
-	hf->fd = open(buf, OREAD);
+	hf->fd = open(buf, OREAD|OCEXEC);
 	if(hf->fd >= 0){
 		hf->len = 0;
 		hf->off = 0;
 		p = hfread(hf, 0, 2*NDBULLEN);
-		if(p){
+		if(p != nil){
 			hf->dbmtime = NDBGETUL(p);
 			hf->hlen = NDBGETUL(p+NDBULLEN);
 			if(hf->dbmtime == db->mtime){
@@ -105,7 +105,7 @@
 	}
 
 	free(hf);
-	return 0;
+	return nil;
 }
 
 /*
@@ -162,7 +162,7 @@
 		if(strcmp(attr, nt->attr) == 0
 		&& strcmp(val, nt->val) == 0)
 			return nt;
-	return 0;
+	return nil;
 }
 
 /*
--- a/sys/src/libndb/ndbopen.c
+++ b/sys/src/libndb/ndbopen.c
@@ -99,7 +99,7 @@
 	}
 
 	/* try the open again */
-	fd = open(db->file, OREAD);
+	fd = open(db->file, OREAD|OCEXEC);
 	if(fd < 0)
 		return -1;
 	d = dirfstat(fd);