Changeset 626f420 in code for cmd.c


Ignore:
Timestamp:
Mar 4, 2014, 5:09:42 PM (11 years ago)
Author:
Mike Belopuhov <mike@…>
Branches:
master
Children:
b7bc432
Parents:
8ef8c4e
git-author:
Mike Belopuhov <mike@…> (03/04/14 17:09:08)
git-committer:
Mike Belopuhov <mike@…> (03/04/14 17:09:42)
Message:

Add icb_vis to escape '%' chars and do some other sanitizing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cmd.c

    r8ef8c4e r626f420  
    2222#include <syslog.h>
    2323#include <unistd.h>
     24#include <vis.h>
    2425#include <event.h>
    2526
     
    7980        struct icb_group *ig = is->group;
    8081        struct icb_session *s;
     82        char whom[ICB_MAXNICKLEN];
    8183
    8284        if (strlen(arg) == 0) {
     
    8587        }
    8688
     89        icb_vis(whom, arg, ICB_MAXNICKLEN);
     90
    8791        LIST_FOREACH(s, &ig->sess, entry) {
    88                 if (strcmp(s->nick, arg) == 0)
     92                if (strcmp(s->nick, whom) == 0)
    8993                        break;
    9094        }
    9195        if (s == NULL) {
    92                 icb_status(is, STATUS_NOTIFY, "%s is not signed on", arg);
     96                icb_status(is, STATUS_NOTIFY, "%s is not signed on", whom);
    9397                return;
    9498        }
     
    110114        struct icb_group *ig;
    111115        struct icb_session *s;
     116        char whom[ICB_MAXNICKLEN];
    112117
    113118        /* to boot or not to boot, that is the question */
     
    119124        }
    120125
     126        if (strlen(whom) == 0) {
     127                icb_error(is, "Invalid user");
     128                return;
     129        }
     130
     131        icb_vis(whom, arg, ICB_MAXNICKLEN);
     132
    121133        /* who would be a target then? */
    122134        LIST_FOREACH(s, &ig->sess, entry) {
    123                 if (strcmp(s->nick, arg) == 0)
     135                if (strcmp(s->nick, whom) == 0)
    124136                        break;
    125137        }
     
    140152        struct icb_group *ig;
    141153        struct icb_session *s;
     154        char group[ICB_MAXGRPLEN];
    142155        int changing = 0;
    143156
     
    147160        }
    148161
     162        icb_vis(group, arg, ICB_MAXGRPLEN);
     163
    149164        LIST_FOREACH(ig, &groups, entry) {
    150                 if (strcmp(ig->name, arg) == 0)
     165                if (strcmp(ig->name, group) == 0)
    151166                        break;
    152167        }
     
    156171                        return;
    157172                } else {
    158                         if ((ig = icb_addgroup(is, arg, NULL)) == NULL) {
     173                        if ((ig = icb_addgroup(is, group, NULL)) == NULL) {
    159174                                icb_error(is, "Can't create group");
    160175                                return;
    161176                        }
    162177                        icb_log(NULL, LOG_DEBUG, "%s created group %s",
    163                             is->nick, arg);
     178                            is->nick, group);
    164179                }
    165180        }
     
    208223        struct icb_group *ig = is->group;
    209224        struct icb_session *s;
     225        char nick[ICB_MAXNICKLEN];
    210226
    211227        if (strlen(arg) == 0) {
     
    221237        if (strlen(arg) > ICB_MAXNICKLEN)
    222238                arg[ICB_MAXNICKLEN - 1] = '\0';
     239        icb_vis(nick, arg, ICB_MAXNICKLEN);
    223240        LIST_FOREACH(s, &ig->sess, entry) {
    224                 if (strcmp(s->nick, arg) == 0) {
     241                if (strcmp(s->nick, nick) == 0) {
    225242                        icb_error(is, "Nick is already in use");
    226243                        return;
     
    228245        }
    229246        icb_status_group(ig, NULL, STATUS_NAME,
    230             "%s changed nickname to %s", is->nick, arg);
    231         strlcpy(is->nick, arg, sizeof is->nick);
     247            "%s changed nickname to %s", is->nick, nick);
     248        strlcpy(is->nick, nick, sizeof is->nick);
    232249}
    233250
     
    284301        struct icb_group *ig = is->group;
    285302        struct icb_session *s;
     303        char whom[ICB_MAXNICKLEN];
    286304
    287305        if (!ig->mod) {         /* if there is no mod, let anyone grab it */
     
    294312                        return;
    295313                }
     314                icb_vis(whom, arg, ICB_MAXNICKLEN);
    296315                LIST_FOREACH(s, &ig->sess, entry) {
    297                         if (strcmp(s->nick, arg) == 0)
     316                        if (strcmp(s->nick, whom) == 0)
    298317                                break;
    299318                }
     
    311330{
    312331        struct icb_group *ig = is->group;
     332        char topic[ICB_MAXTOPICLEN];
    313333
    314334        if (strlen(arg) == 0) { /* querying the topic */
     
    324344                        return;
    325345                }
    326                 strlcpy(ig->topic, arg, sizeof ig->topic);
     346                icb_vis(topic, arg, ICB_MAXTOPICLEN);
     347                strlcpy(ig->topic, topic, sizeof ig->topic);
    327348                icb_status_group(ig, NULL, STATUS_TOPIC,
    328349                    "%s changed the topic to \"%s\"", is->nick, ig->topic);
     
    334355{
    335356        struct icb_group *ig;
     357        char group[ICB_MAXGRPLEN];
    336358
    337359        if (strlen(arg) == 0)
    338360                return icb_who(is, NULL);
    339361
     362        icb_vis(group, arg, ICB_MAXGRPLEN);
    340363        LIST_FOREACH(ig, &groups, entry) {
    341                 if (strcmp(ig->name, arg) == 0)
     364                if (strcmp(ig->name, group) == 0)
    342365                        break;
    343366        }
    344367        if (ig == NULL) {
    345                 icb_error(is, "The group %s doesn't exist.", arg);
     368                icb_error(is, "The group %s doesn't exist.", group);
    346369                return;
    347370        }
Note: See TracChangeset for help on using the changeset viewer.