Skip to contentSkip to conversation

fsidd: replace assertions with explicit malformed-input handling

PATCH In review Scott Mayhew 2 participants 2 messages Sep 3 – Sep 16

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fsidd: replace assertions with explicit malformed-input handling

fsidd relies on assert() to ensure that an argument is present after the command prefix while parsing commands received over the local socket. Malformed input can cause fsidd to abort. Replace the assertions with explicit malformed-input handling and return an error to the client.

---
 support/reexport/fsidd.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
support/reexport/fsidd.c +15 -4
index 51750ea3..f5c397aa 100644
@@ -48,7 +48,11 @@ static void client_cb(evutil_socket_t cl, short ev, void *d)
 		char *answer = NULL;
 		bool found;
 
-		assert(req_path < buf + n );
+		if (req_path >= buf + n) {
+			char answer[] = "- Command failed: Bad input";
+			(void)send(cl, answer, strlen(answer), 0);
+			return;
+		}
 
 		printf("client asks for %s\n", req_path);
 
@@ -70,8 +74,11 @@ static void client_cb(evutil_socket_t cl, short ev, void *d)
 		char *answer = NULL;
 		bool found;
 
-		assert(req_path < buf + n );
-
+		if (req_path >= buf + n) {
+			char answer[] = "- Command failed: Bad input";
+			(void)send(cl, answer, strlen(answer), 0);
+			return;
+		}
 
 		if (dbbackend->fsidnum_by_path(req_path, &fsidnum, true, &found)) {
 			if (found) {
@@ -94,7 +101,11 @@ static void client_cb(evutil_socket_t cl, short ev, void *d)
 		uint32_t fsidnum;
 		bool found;
 
-		assert(req_fsidnum < buf + n );
+		if (req_fsidnum >= buf + n) {
+			char answer[] = "- Command failed: Bad input";
+			(void)send(cl, answer, strlen(answer), 0);
+			return;
+		}
 
 		errno = 0;
 		fsidnum = strtoul(req_fsidnum, &endp, 10);
Signature · 1 line
2.55.0
#1 lore raw
Quoted 6 lines · Scott Mayhew

fsidd relies on assert() to ensure that an argument is present after the command prefix while parsing commands received over the local socket. Malformed input can cause fsidd to abort. Replace the assertions with explicit malformed-input handling and return an error to the client.

Committed... (tag: nfs-utils-2-9-3-rc4)

steved.

Quoted 48 lines
---
  support/reexport/fsidd.c | 19 +++++++++++++++----
  1 file changed, 15 insertions(+), 4 deletions(-)
support/reexport/fsidd.c +15 -4
index 51750ea3..f5c397aa 100644
@@ -48,7 +48,11 @@ static void client_cb(evutil_socket_t cl, short ev, void *d)
  		char *answer = NULL;
  		bool found;
 
-		assert(req_path < buf + n );
+		if (req_path >= buf + n) {
+			char answer[] = "- Command failed: Bad input";
+			(void)send(cl, answer, strlen(answer), 0);
+			return;
+		}
 
  		printf("client asks for %s\n", req_path);
 
@@ -70,8 +74,11 @@ static void client_cb(evutil_socket_t cl, short ev, void *d)
  		char *answer = NULL;
  		bool found;
 
-		assert(req_path < buf + n );
-
+		if (req_path >= buf + n) {
+			char answer[] = "- Command failed: Bad input";
+			(void)send(cl, answer, strlen(answer), 0);
+			return;
+		}
 
  		if (dbbackend->fsidnum_by_path(req_path, &fsidnum, true, &found)) {
  			if (found) {
@@ -94,7 +101,11 @@ static void client_cb(evutil_socket_t cl, short ev, void *d)
  		uint32_t fsidnum;
  		bool found;
 
-		assert(req_fsidnum < buf + n );
+		if (req_fsidnum >= buf + n) {
+			char answer[] = "- Command failed: Bad input";
+			(void)send(cl, answer, strlen(answer), 0);
+			return;
+		}
 
  		errno = 0;
  		fsidnum = strtoul(req_fsidnum, &endp, 10);