]> jfr.im git - irc/quakenet/newserv.git/blobdiff - localuser/localuserchannel.c
Add memory protection to debug version of (old) sstring.
[irc/quakenet/newserv.git] / localuser / localuserchannel.c
index 18ed37a72f0a3ab0802586b48c61c783e5005a5c..59c2a841180a08aa513ba6208b3e4014f46b2bd9 100644 (file)
@@ -236,7 +236,11 @@ int localburstontochannel(channel *cp, nick *np, time_t timestamp, flag_t modes,
     /* deal with key - if we need one use the provided one if set, otherwise
      * the existing one, but if there is no existing one clear +k */
     if (IsKey(cp)) {
-      if (key) {
+      /* Sanitise the provided key - this might invalidate it.. */
+      if (key)
+        clean_key(key);
+        
+      if (key && *key) {
         /* Free old key, if any */
         if (cp->key)
           freesstring(cp->key);
@@ -510,7 +514,7 @@ void localdosetmode_ban (modechanges *changes, const char *ban, short dir) {
  *  Set or clear a key on the channel
  */
 
-void localdosetmode_key (modechanges *changes, const char *key, short dir) {
+void localdosetmode_key (modechanges *changes, char *key, short dir) {
   int i,j;
   sstring *keysstr;
 
@@ -519,6 +523,11 @@ void localdosetmode_key (modechanges *changes, const char *key, short dir) {
     localsetmodeflush(changes,0);
 
   if (dir==MCB_ADD) {
+    /* Sanitise the key.  If this nullifies it then we give up */
+    clean_key(key);
+    if (!*key)
+      return;
+
     /* Get a copy of the key for use later */
     keysstr=getsstring(key, KEYLEN);
     
@@ -535,6 +544,7 @@ void localdosetmode_key (modechanges *changes, const char *key, short dir) {
          freesstring(changes->cp->key);
          changes->cp->key=getsstring(key, KEYLEN);
          /* That's it, we're done */
+         freesstring(keysstr);
          return;
        } else {
          /* There was a command to delete key.. we need to flush 
@@ -877,6 +887,7 @@ void localusermodechange(nick *np, channel *cp, char *modes) {
 void localsettopic(nick *np, channel *cp, char *topic) {
   unsigned long *lp;
   char source[10];
+  time_t now=getnettime();
 
   if (np==NULL || (lp=getnumerichandlefromchanhash(cp->users,np->numeric))==NULL) {
     /* User isn't on channel, hack mode */
@@ -897,7 +908,13 @@ void localsettopic(nick *np, channel *cp, char *topic) {
   }
 
   cp->topic=getsstring(topic,TOPICLEN);
-  cp->topictime=getnettime();
+
+  /* Update the topic time iff the old time was in the past.  This 
+   * means if we are bouncing a topic with a TS 1sec newer than ours 
+   * we won't use an old timestamp */
+  if (cp->topictime < now) {
+    cp->topictime=now;
+  }
   
   if (connected) {
     irc_send("%s T %s %u %u :%s",source,cp->index->name->content,cp->timestamp,cp->topictime,(cp->topic)?cp->topic->content:"");