浏览代码

* Ensure buffer exists to prevent buffer[-1] writing

Bryan Drewery 16 年之前
父节点
当前提交
972fc66c75
共有 2 个文件被更改,包括 3 次插入3 次删除
  1. 1 1
      src/main.c
  2. 2 2
      src/net.c

+ 1 - 1
src/main.c

@@ -141,7 +141,7 @@ static char *getfullbinname(const char *argv_zero)
   if (!getcwd(cwd, PATH_MAX))
   if (!getcwd(cwd, PATH_MAX))
     fatal(STR("getcwd() failed"), 0);
     fatal(STR("getcwd() failed"), 0);
 
 
-  if (cwd[strlen(cwd) - 1] == '/')
+  if (cwd[0] && cwd[strlen(cwd) - 1] == '/')
     cwd[strlen(cwd) - 1] = 0;
     cwd[strlen(cwd) - 1] = 0;
 
 
   p = bin;
   p = bin;

+ 2 - 2
src/net.c

@@ -1065,7 +1065,7 @@ int sockgets(char *s, int *len)
 	    socklist[i].inbuf = NULL;
 	    socklist[i].inbuf = NULL;
 	  }
 	  }
 	  /* Strip CR if this was CR/LF combo */
 	  /* Strip CR if this was CR/LF combo */
-	  if (s[strlen(s) - 1] == '\r')
+	  if (strlen(s) && s[strlen(s) - 1] == '\r')
 	    s[strlen(s) - 1] = 0;
 	    s[strlen(s) - 1] = 0;
 
 
           if (s[0] && socklist[i].encstatus)
           if (s[0] && socklist[i].encstatus)
@@ -1179,7 +1179,7 @@ int sockgets(char *s, int *len)
     memmove(xx, p + 1, strlen(p + 1) + 1);
     memmove(xx, p + 1, strlen(p + 1) + 1);
 
 
 /*    if (s[0] && strlen(s) && (s[strlen(s) - 1] == '\r')) */
 /*    if (s[0] && strlen(s) && (s[strlen(s) - 1] == '\r')) */
-    if (s[strlen(s) - 1] == '\r')
+    if (strlen(s) && s[strlen(s) - 1] == '\r')
       s[strlen(s) - 1] = 0;
       s[strlen(s) - 1] = 0;
     data = 1;			/* DCC_CHAT may now need to process a blank line */
     data = 1;			/* DCC_CHAT may now need to process a blank line */
 /* NO! */
 /* NO! */