浏览代码

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)
Daniel-Constantin Mierla 5 年之前
父节点
当前提交
f82bdb7fad
共有 1 个文件被更改,包括 3 次插入5 次删除
  1. 3 5
      src/modules/xcap_server/xcap_server.c

+ 3 - 5
src/modules/xcap_server/xcap_server.c

@@ -319,14 +319,12 @@ int xcaps_xpath_hack(str *buf, int type)
 	}
 
 	start = buf->s;
-	c = buf->s[buf->len-1];
-	buf->s[buf->len-1] = '\0';
-	while((p = strstr(start, match))!=NULL)
-	{
+	STR_VTOZ(buf->s[buf->len-1], c);
+	while((start < buf->s + buf->len - 8) && (p = strstr(start, match))!=NULL) {
 		memcpy(p, repl, 7);
 		start = p + 7;
 	}
-	buf->s[buf->len-1] = c;
+	STR_ZTOV(buf->s[buf->len-1], c);
 	return 0;
 }