Browse Source

* Fixes from eggdrop cvs
* Fixed bugs wild_match(), rmspace(), n_free()
* Added remove_crlf
* Fixed security hole in share.mod
* Small notes.mod fix


svn: 400

Eggheads Development Team (Ported by Bryan) 23 năm trước cách đây
mục cha
commit
4c94dd4ebd
12 tập tin đã thay đổi với 56 bổ sung và 17 xóa
  1. 10 6
      src/chanprog.c
  2. 1 1
      src/main.c
  3. 12 0
      src/match.c
  4. 7 4
      src/mem.c
  5. 12 0
      src/misc.c
  6. 1 1
      src/mod/module.h
  7. 1 1
      src/mod/notes.mod/notes.c
  8. 6 0
      src/mod/server.mod/server.h
  9. 3 2
      src/mod/share.mod/share.c
  10. 1 1
      src/modules.c
  11. 1 0
      src/proto.h
  12. 1 1
      src/userrec.c

+ 10 - 6
src/chanprog.c

@@ -54,17 +54,21 @@ void rmspace(char *s)
 {
 #define whitespace(c) (((c) == 32) || ((c) == 9) || ((c) == 13) || ((c) == 10))
   char *p;
+  int len;
 
-  if (*s == '\0')
-	return;
+  if (!*s)
+    return;
 
   /* Wipe end of string */
   for (p = s + strlen(s) - 1; ((whitespace(*p)) && (p >= s)); p--);
-  if (p != s + strlen(s) - 1)
-    *(p + 1) = 0;
+  *(p + 1) = 0;
+  len = p+1 - s;
   for (p = s; ((whitespace(*p)) && (*p)); p++);
-  if (p != s)
-    strcpy(s, p);
+  len -= (p - s);
+  if (p != s) {
+    /* +1 to include the null in the copy */
+    memmove(s, p, len+1);
+  }
 }
 
 /* Returns memberfields if the nick is in the member list.

+ 1 - 1
src/main.c

@@ -281,7 +281,7 @@ void write_debug()
     strncpyz(s, ctime(&now), sizeof s);
     dprintf(-x, "Debug (%s) written %s\n", ver, s);
 
-    egg_stftime(date, sizeof date, "%c %Z", gmtime(&buildts));
+    egg_strftime(date, sizeof date, "%c %Z", gmtime(&buildts));
     dprintf(-x, "Build: %s (%lu)\n", date, buildts);
     /* info library */
     dprintf(-x, "Tcl library: %s\n",

+ 12 - 0
src/match.c

@@ -144,6 +144,17 @@ int _wild_match(register unsigned char *m, register unsigned char *n)
   n--;
 
   while (n >= na) {
+    /* If the mask runs out of chars before the string, fall back on
+     * a wildcard or fail. */
+    if (m < ma) {
+      if (lsm) {
+        n = --lsn;
+        m = lsm;
+        if (n < na) lsm = 0;
+        sofar = 0;
+      }
+      else return NOMATCH;
+    }
     switch (*m) {
     case WILDS:                /* Matches anything */
       do
@@ -153,6 +164,7 @@ int _wild_match(register unsigned char *m, register unsigned char *n)
       lsn = n;
       match += sofar;
       sofar = 0;                /* Update fallback pos */
+      if (m < ma) return MATCH;
       continue;                 /* Next char, please */
     case WILDQ:
       m--;

+ 7 - 4
src/mem.c

@@ -419,10 +419,13 @@ void n_free(void *ptr, const char *file, int line)
     }
     memused -= memtbl[i].size;
     lastused--;
-    memtbl[i].ptr = memtbl[lastused].ptr;
-    memtbl[i].size = memtbl[lastused].size;
-    memtbl[i].line = memtbl[lastused].line;
-    strcpy(memtbl[i].file, memtbl[lastused].file);
+    /* We don't want any holes, so if this wasn't the last entry, swap it. */
+    if (i != lastused) {
+      memtbl[i].ptr = memtbl[lastused].ptr;
+      memtbl[i].size = memtbl[lastused].size;
+      memtbl[i].line = memtbl[lastused].line;
+      strcpy(memtbl[i].file, memtbl[lastused].file);
+    }
   }
 #endif
   free(ptr);

+ 12 - 0
src/misc.c

@@ -213,6 +213,18 @@ char *splitnick(char **blah)
   return "";
 }
 
+void remove_crlf(char **line)
+{
+  char *p;
+
+  p = strchr(*line, '\n');
+  if (p != NULL)
+    *p = 0;
+  p = strchr(*line, '\r');
+  if (p != NULL)
+    *p = 0;
+}
+
 char *newsplit(char **rest)
 {
   register char *o, *r;

+ 1 - 1
src/mod/module.h

@@ -136,7 +136,7 @@
 /* 28 - 31 */
 #define botnet_send_chat ((void(*)(int,char*,char*))global[28])
 #define server_lag (*(int *)global[29])
-/* UNUSED 30 */
+#define remove_crlf ((void (*)(char **))global[30])
 /* UNUSED 31 */
 /* 32 - 35 */
 #define botnet_send_join_idx ((void(*)(int,int))global[32])

+ 1 - 1
src/mod/notes.mod/notes.c

@@ -267,7 +267,7 @@ static void notes_read(char *hand, char *nick, char *srd, int idx)
   while (!feof(f)) {
     fgets(s, 600, f);
     i = strlen(s);
-    if (i && s[i - 1] == '\n')
+    if (i > 0 && s[i - 1] == '\n')
       s[i - 1] = 0;
     if (!feof(f)) {
       rmspace(s);

+ 6 - 0
src/mod/server.mod/server.h

@@ -69,6 +69,12 @@
 	ptr = NULL;					\
 } while (0)
 
+#define write_to_server(x,y) do {                       \
+        tputs(serv, (x), (y));                          \
+        tputs(serv, "\r\n", 2);                         \
+} while (0)
+
+
 #endif		/* MAKING_SERVER */
 
 struct server_list {

+ 3 - 2
src/mod/share.mod/share.c

@@ -1477,9 +1477,10 @@ static void check_expired_tbufs()
 	}
 	/* If it's a share bot that hasnt been sharing, ask again */
       } else if (!(dcc[i].status & STAT_SHARE)) {
-	if (dcc[i].user && bot_aggressive_to(dcc[i].user))
+	if (dcc[i].user && bot_aggressive_to(dcc[i].user)) {
 	  dprintf(i, "s u?\n");
-	dcc[i].status |= STAT_OFFERED;
+          dcc[i].status |= STAT_OFFERED;
+        }
       }
     }
 }

+ 1 - 1
src/modules.c

@@ -192,7 +192,7 @@ Function global_table[] =
   /* 28 - 31 */
   (Function) botnet_send_chat,
   (Function) & server_lag, /* int					*/
-  (Function) 0,
+  (Function) remove_crlf,
   (Function) 0,
   /* 32 - 35 */
   (Function) botnet_send_join_idx,

+ 1 - 0
src/proto.h

@@ -264,6 +264,7 @@ void maskhost(const char *, char *);
 char *stristr(char *, char *);
 void splitc(char *, char *, char);
 void splitcn(char *, char *, char, size_t);
+void remove_crlf(char **);
 char *newsplit(char **);
 char *splitnick(char **);
 void stridx(char *, char *, int);

+ 1 - 1
src/userrec.c

@@ -233,7 +233,7 @@ void correct_handle(char *handle)
   struct userrec *u;
 
   u = get_user_by_handle(userlist, handle);
-  if (u == NULL)
+  if (u == NULL || handle == u->handle)
     return;
   strcpy(handle, u->handle);
 }