[hackers] ii: new tip (= 48)

From: Anselm R. Garbe <arg_AT_suckless.org>
Date: Thu, 01 Feb 2007 11:30:02 +0100

changeset: 48:d37be8e442a2
tag: tip
user: nion_AT_h4447.serverkompetenz.net
date: Thu Feb 01 11:21:52 2007 +0100
files: ii.c
description:
harden ii a bit

diff -r d0f27dc8e4ba -r d37be8e442a2 ii.c
--- a/ii.c Thu Feb 01 11:04:47 2007 +0100
+++ b/ii.c Thu Feb 01 11:21:52 2007 +0100
@@ -231,6 +231,7 @@ static void proc_channels_input(Channel
                 proc_channels_privmsg(c->name, buf);
                 return;
         }
+ message[0] = '\0';
         switch (buf[1]) {
                 case 'j':
                         p = strchr(&buf[3], ' ');
@@ -248,24 +249,28 @@ static void proc_channels_input(Channel
                         }
                         break;
                 case 't':
- snprintf(message, PIPE_BUF, "TOPIC %s :%s\r\n", c->name, &buf[3]);
+ if(strlen(buf)>=3) snprintf(message, PIPE_BUF, "TOPIC %s :%s\r\n", c->name, &buf[3]);
                         break;
                 case 'a':
- snprintf(message, PIPE_BUF, "-!- %s is away \"%s\"", nick, &buf[3]);
- print_out(c->name, message);
- if(buf[2] == 0)
+ if(strlen(buf)>=3){
+ snprintf(message, PIPE_BUF, "-!- %s is away \"%s\"", nick, &buf[3]);
+ print_out(c->name, message);
+ }
+ if(buf[2] == 0 || strlen(buf)<3) /* or used to make else part safe */
                                 snprintf(message, PIPE_BUF, "AWAY\r\n");
                         else
                                 snprintf(message, PIPE_BUF, "AWAY :%s\r\n", &buf[3]);
                         break;
                 case 'n':
- snprintf(nick, sizeof(nick),"%s", &buf[3]);
- snprintf(message, PIPE_BUF, "NICK %s\r\n", &buf[3]);
+ if(strlen(buf)>=3){
+ snprintf(nick, sizeof(nick),"%s", &buf[3]);
+ snprintf(message, PIPE_BUF, "NICK %s\r\n", &buf[3]);
+ }
                         break;
                 case 'l':
                         if(c->name[0] == 0)
                                 return;
- if(buf[2] == ' ')
+ if(buf[2] == ' ' && strlen(buf)>=3)
                                 snprintf(message, PIPE_BUF, "PART %s :%s\r\n", c->name, &buf[3]);
                         else
                                 snprintf(message, PIPE_BUF,
@@ -281,7 +286,8 @@ static void proc_channels_input(Channel
                         snprintf(message, PIPE_BUF, "%s\r\n", &buf[1]);
                         break;
         }
- write(irc, message, strlen(message));
+ if (message[0] != '\0')
+ write(irc, message, strlen(message));
 }
 
 static void proc_server_cmd(char *buf) {
Received on Thu Feb 01 2007 - 11:30:02 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:54:49 UTC