Selaa lähdekoodia

* Ported [2901] to 1.2.11
* Aliases may no longer reference other aliases (only checked when used) (fixes #244)


svn: 2902

Bryan Drewery 20 vuotta sitten
vanhempi
commit
6c0d6c593d
3 muutettua tiedostoa jossa 22 lisäystä ja 4 poistoa
  1. 1 0
      doc/UPDATES
  2. 2 2
      misc/help.txt
  3. 19 2
      src/core_binds.c

+ 1 - 0
doc/UPDATES

@@ -7,6 +7,7 @@ Lines prefixed with '-' were disabled before release and are not finished, or ar
 * Fixed a bug in cmd_chattr with |m users. (fixes #267)
 * Suicide now removes userfile backups, most pid files, and crontab entries. (Fixes #125)
 * Fixed removed bots not being automatically unlinked from botnet. (fixes #254)
+* Aliases may no longer reference other aliases (only checked when used) (fixes #244)
 
 1.2.10 - http://tracker.shatow.net/milestone/1.2.10
 * Removed old references to '+/-manop' and '+/-nomop' for chaninfo in help file.

+ 2 - 2
misc/help.txt

@@ -1481,8 +1481,8 @@ See also: reload, backup
  
 [SL] $balias$b           List of dcc aliases in format '<alias> <cmd> [parms]'. First
                           matching alias is used. Normal flag checking is done
-                          after the alias is expanded.
-                          $fCAUTION: TRIPPLE CHECK FOR POSSIBLE LOOPS AS THEY ARE FATAL.$f
+                          after the alias is expanded. 
+                          $bAliases may not reference other aliases.$b
 [S]  $bchanset$b         List of default options for when a channel is added. Same format 
                           as 'chanset'.
 [N]  $bserver-port$b     Default port to use for server connections.

+ 19 - 2
src/core_binds.c

@@ -43,6 +43,8 @@ bool check_aliases(int idx, const char *cmd, const char *args)
 {
   char *a = NULL, *p = NULL, *aliasp = NULL, *aliasdup = NULL, *argsp = NULL, *argsdup = NULL;
   bool found = 0;
+  bind_entry_t *entry = NULL;
+  bind_table_t *table = NULL;
 
   aliasp = aliasdup = strdup(alias);
   argsp = argsdup = strdup(args);
@@ -71,8 +73,23 @@ bool check_aliases(int idx, const char *cmd, const char *args)
         simple_snprintf(myargs, size, "%s %s %s", pass, a, argsdup);
       } else
         simple_snprintf(myargs, size, "%s %s", a, argsdup);
-      putlog(LOG_CMDS, "*", "@ #%s# [%s -> %s %s] ...", dcc[idx].nick, cmd, p, a);
-      check_bind_dcc(p, idx, myargs);
+
+      /* Sanity check - Aliases cannot reference another alias */
+      bool find = 0;
+      table = bind_table_lookup("dcc");
+      for (entry = table->entries; entry && entry->next; entry = entry->next) {
+        if (!egg_strncasecmp(p, entry->mask, strlen(p))) {
+          find = 1;
+          break;
+        }
+      }
+      if (!find) {
+        dprintf(idx, "'%s' is an invalid alias: references alias '%s'.\n", cmd, p);
+        putlog(LOG_ERROR, "*", "Invalid alias '%s' attempted: references alias '%s'.", cmd, p);
+      } else {
+        putlog(LOG_CMDS, "*", "@ #%s# [%s -> %s %s] ...", dcc[idx].nick, cmd, p, a);
+        check_bind_dcc(p, idx, myargs);
+      }
 
       if (myargs)
         free(myargs);