Browse code

xcap_server: check before going to the end of the buffer

- use marcros to set and restore char for ending 0

(cherry picked from commit 6ce5c0bdf136ecffd7917f2d60093e1b2c49fa54)
(cherry picked from commit 4aeb071b26df08e1dfc902340475c077e468c661)

Daniel-Constantin Mierla authored on 31/07/2020 18:45:47
Showing 1 changed files
... ...
@@ -321,14 +321,12 @@ int xcaps_xpath_hack(str *buf, int type)
321 321
 	}
322 322
 
323 323
 	start = buf->s;
324
-	c = buf->s[buf->len-1];
325
-	buf->s[buf->len-1] = '\0';
326
-	while((p = strstr(start, match))!=NULL)
327
-	{
324
+	STR_VTOZ(buf->s[buf->len-1], c);
325
+	while((start < buf->s + buf->len - 8) && (p = strstr(start, match))!=NULL) {
328 326
 		memcpy(p, repl, 7);
329 327
 		start = p + 7;
330 328
 	}
331
-	buf->s[buf->len-1] = c;
329
+	STR_ZTOV(buf->s[buf->len-1], c);
332 330
 	return 0;
333 331
 }
334 332