diff rvinterf/etmsync/fsbasics.c @ 295:3dd74b16df82

fc-fsio: pathname recursion handling revamped
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sat, 01 Mar 2014 08:01:08 +0000
parents 244f08f58e51
children d1333db6385f
line wrap: on
line diff
--- a/rvinterf/etmsync/fsbasics.c	Sat Mar 01 04:04:20 2014 +0000
+++ b/rvinterf/etmsync/fsbasics.c	Sat Mar 01 08:01:08 2014 +0000
@@ -11,6 +11,7 @@
 #include "ffs.h"
 #include "tmffs2.h"
 #include "limits.h"
+#include "ffslimits.h"
 #include "localtypes.h"
 #include "localstruct.h"
 #include "exitcodes.h"
@@ -75,7 +76,7 @@
 	return(0);
 }
 
-do_readdir(state, namebuf)
+do_readdir(state, namebuf, namebuflen)
 	u_char *state;
 	char *namebuf;
 {
@@ -101,8 +102,12 @@
 	if (rvi_msg[5] != 4)
 		goto malformed;
 	slen = rvi_msg[10];
-	if (slen < 2 || slen > TMFFS_STRING_SIZE)
+	if (slen < 2 || rvi_msg_len != slen + 12)
 		goto malformed;
+	if (slen > namebuflen) {
+		printf("error: readdir response exceeds provided buffer\n");
+		return(ERROR_TARGET);
+	}
 	if (rvi_msg[11 + slen - 1])	/* must be terminating NUL */
 		goto malformed;
 	bcopy(rvi_msg + 6, state, 4);
@@ -114,7 +119,7 @@
 	char **argv;
 {
 	u_char state[4];
-	char namebuf[TMFFS_STRING_SIZE];
+	char namebuf[256];
 	int nument, i, rc;
 
 	rc = do_opendir(argv[1], state, &nument);
@@ -125,7 +130,7 @@
 		return(0);
 	}
 	for (i = 0; i < nument; i++) {
-		rc = do_readdir(state, namebuf);
+		rc = do_readdir(state, namebuf, sizeof namebuf);
 		if (rc)
 			return(rc);
 		printf("%s\n", namebuf);