Hi again,

Sorry to bother about this again. I noticed a couple more cases we can have
trailing spaces, so I updated my patch to account for them.

The first new case is the MODE command. You can see a single trailing space
when you remove a single mode without a parameter. It can happen with
several modes, as long as you don't have a parameter. Example: MODE #test
-t.

The second new case you can see when servers connect and the server removes
modes, such as if a client gained ops during a netsplit. It will only arise
in mode lines not hitting the max mode count.

I made similar changes to the first for these in the patch. I also looked
to see if I could find any more such cases (at least in messages sent to
clients), and have been unable to see any.

I've also realized that the IRC RFCs aren't widely followed, so changing
for them doesn't make a lot of sense. But since these trailing characters
are not needed, I figure there's no point sending them either way.

Thank you.

On Wed 2016-09-07 22:25:30 -0700, Will Storey wrote:
> Hi,
> 
> I noticed that there are trailing spaces in some cases in the MODE messages
> sent by servers when processing an SJOIN message. I saw this happen when
> servers join and modes got bursted over.
> 
> Here is an example of what I mean (message wrapped in [] to show spaces):
> 
> [:test.summercat.com MODE #test +o will   ]
> 
> I traced this to ms_sjoin() where there is this format string:
> 
> ":%s MODE %s %s %s %s %s %s"
> 
> The last 3 %s arguments may be blank which leads to these trailing spaces.
> 
> It is not exactly a huge problem I know. I only ran into it as I was basing
> some parsing code off RFC 2812's grammar. In RFC 1459 this appears possibly
> valid, but not in RFC 2812. Perhaps it is still worth making a small update
> for though.
> 
> I have attached a diff with a possible solution.
> 
> Thank you for your time.

> --- modules/core/m_join.c     (revision 29442)
> +++ modules/core/m_join.c     (working copy)
> @@ -812,10 +812,12 @@
>       if(pargs)
>       {
>               sendto_channel_local(ALL_MEMBERS, chptr,
> -                                  ":%s MODE %s %s %s %s %s %s",
> +                                  ":%s MODE %s %s %s%s%s%s%s%s%s",
>                                    source_p->name, chptr->chname, modebuf,
> -                                  para[0], CheckEmpty(para[1]), 
> CheckEmpty(para[2]),
> -                                  CheckEmpty(para[3]));
> +                                  para[0],
> +                                  EmptyString(para[1]) ? "" : " ", 
> CheckEmpty(para[1]),
> +                                  EmptyString(para[2]) ? "" : " ", 
> CheckEmpty(para[2]),
> +                                  EmptyString(para[3]) ? "" : " ", 
> CheckEmpty(para[3]));
>       }
>  
>       if(!joins)

Index: modules/core/m_join.c
===================================================================
--- modules/core/m_join.c	(revision 29442)
+++ modules/core/m_join.c	(working copy)
@@ -812,10 +812,12 @@
 	if(pargs)
 	{
 		sendto_channel_local(ALL_MEMBERS, chptr,
-				     ":%s MODE %s %s %s %s %s %s",
+				     ":%s MODE %s %s %s%s%s%s%s%s%s",
 				     source_p->name, chptr->chname, modebuf,
-				     para[0], CheckEmpty(para[1]), CheckEmpty(para[2]),
-				     CheckEmpty(para[3]));
+				     para[0],
+				     EmptyString(para[1]) ? "" : " ", CheckEmpty(para[1]),
+				     EmptyString(para[2]) ? "" : " ", CheckEmpty(para[2]),
+				     EmptyString(para[3]) ? "" : " ", CheckEmpty(para[3]));
 	}
 
 	if(!joins)
@@ -1204,11 +1206,14 @@
 	{
 		*mbuf = '\0';
 		sendto_channel_local(ALL_MEMBERS, chptr,
-				     ":%s MODE %s %s %s %s %s %s",
+				     ":%s MODE %s %s %s%s%s%s%s%s%s",
 				     me.name, chptr->chname, lmodebuf,
 				     EmptyString(lpara[0]) ? "" : lpara[0],
+				     EmptyString(lpara[1]) ? "" : " ",
 				     EmptyString(lpara[1]) ? "" : lpara[1],
+				     EmptyString(lpara[2]) ? "" : " ",
 				     EmptyString(lpara[2]) ? "" : lpara[2],
+				     EmptyString(lpara[3]) ? "" : " ",
 				     EmptyString(lpara[3]) ? "" : lpara[3]);
 	}
 }
Index: modules/core/m_mode.c
===================================================================
--- modules/core/m_mode.c	(revision 29442)
+++ modules/core/m_mode.c	(working copy)
@@ -1537,7 +1537,8 @@
 
 		*mbuf = '\0';
 		if(cur_len > mlen)
-			sendto_channel_local(flags, chptr, "%s %s", modebuf, parabuf);
+			sendto_channel_local(flags, chptr, "%s%s%s", modebuf,
+					EmptyString(parabuf) ? "" : " ", parabuf);
 	}
 
 	/* only propagate modes originating locally, or if we're hubbing */
_______________________________________________
ircd-ratbox mailing list
ircd-ratbox@lists.ratbox.org
http://lists.ratbox.org/cgi-bin/mailman/listinfo/ircd-ratbox

Reply via email to