]> jfr.im git - irc/quakenet/newserv.git/blame - chanserv/usercmds/usercomment.c
Made sure we don't call strncpy with a negative length.
[irc/quakenet/newserv.git] / chanserv / usercmds / usercomment.c
CommitLineData
1dd6d55d 1/* Automatically generated by refactor.pl.
2 *
3 *
4 * CMDNAME: usercomment
5 * CMDLEVEL: QCMD_OPER
6 * CMDARGS: 2
7 * CMDDESC: Shows or changes staff comment for a user.
8 * CMDFUNC: csu_dousercomment
9 * CMDPROTO: int csu_dousercomment(void *source, int cargc, char **cargv);
94e4d2f4
CP
10 * CMDHELP: Usage: usercomment <username> [<comment>]
11 * CMDHELP: Shows or changes the staff comment for the specified user.
1dd6d55d 12 */
13
14#include "../chanserv.h"
15#include "../../lib/irc_string.h"
16#include <stdio.h>
17#include <string.h>
18
19int csu_dousercomment(void *source, int cargc, char **cargv) {
20 nick *sender=source;
21 reguser *rup=getreguserfromnick(sender), *target;
22 char buf[300];
23 int bufpos;
24
25 if (!rup)
26 return CMD_ERROR;
27
28 if (cargc<1) {
29 chanservstdmessage(sender, QM_NOTENOUGHPARAMS, "usercomment");
30 return CMD_ERROR;
31 }
32
33 if (!(target=findreguser(sender, cargv[0])))
34 return CMD_ERROR;
35
36 if (cargc>1) {
37 if (!ircd_strcmp(cargv[1],"none")) {
38 freesstring(target->comment);
39 target->comment=NULL;
40 } else {
41 if (*cargv[1]=='+') {
42 if (target->comment) {
43 strcpy(buf,target->comment->content);
44 bufpos=target->comment->length;
45 buf[bufpos++]=' ';
46 } else {
47 bufpos=0;
48 }
15cf23c4 49 strncpy(buf+bufpos, cargv[1]+1, 280-bufpos);
1dd6d55d 50 } else {
51 strncpy(buf, cargv[1], 250);
52 }
53
54 freesstring(target->comment);
55 target->comment=getsstring(buf,250);
56 }
57 csdb_updateuser(target);
58 }
59
60 if (target->comment)
61 chanservstdmessage(sender, QM_COMMENT, target->username, target->comment->content);
62 else
63 chanservstdmessage(sender, QM_NOCOMMENT, target->username);
64
65 return CMD_OK;
66}