From 19c2749eb64171a25ac5a8fb8eab5f73c83bd7f2 Mon Sep 17 00:00:00 2001 From: epochqwert Date: Wed, 4 Feb 2015 03:11:22 -0600 Subject: I don't remember. --- segfault.c | 364 +++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 234 insertions(+), 130 deletions(-) (limited to 'segfault.c') diff --git a/segfault.c b/segfault.c index 41fd2ea..034109f 100644 --- a/segfault.c +++ b/segfault.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include "libirc/irc.h" //epoch's libirc. should be included with segfault. @@ -24,7 +25,6 @@ #define SEGHOMELEN 1024 #define RAWLOG "./files/rawlog" #define LOG "./files/log" -#define MAXTAILS maxtails //just to have it more than the system default. #define BS 4096 // !c uses 56 for its tail. // 56 == 32 + 16 + 8 == 0x38 == 0x20+0x10+0x8 == SPAM | BEGIN | MSG @@ -39,15 +39,16 @@ #define TAILO_Q_EVAL (TAILO_EVAL|TAILO_CLOSE|TAILO_BEGIN) //0x2+0x4+0x10 = 2+4+16 = 22 #define TAILO_Q_COUT (TAILO_SPAM|TAILO_BEGIN|TAILO_MSG) //0x20+0x10+0x8 = 32+16+8 = 56 +#define PRIVMSG_LINE_LIMIT 0 + //this function isn't with the rest of them because... meh. -char *tailmode_to_txt(unsigned short mode) { - char *modes="recmbsn"; +char *tailmode_to_txt(int mode) { + char *modes="recmbsnf"; int i,j=0; char *m=malloc(strlen(modes)); for(i=0;i PRIVMSG_LINE_LIMIT) break; } } //try to shorten this up sometime... char *format_magic(int fd,char *from,struct user *user,char *orig_fmt,char *arg) { - int i,j,sz=0,c=1; + int i=0,j=1,sz=0,c=1; char seghome[SEGHOMELEN]; char *output,*fmt; char **args,**notargs; + char *argCopy; + char *argN[10]; + //lets split up arg? if(!arg) arg="%s"; + if(!(argCopy=strdup(arg))) return 0; + for(argN[j]=argCopy;argCopy[i];i++) { + if(argCopy[i] == ' ') { + argN[j]=argCopy+i; + argN[j][0]=0; + argN[j]++; + j++; + } + } + for(;j<10;j++) { + argN[j]="(null)";//fill up the rest to prevent null deref. + } + if(!orig_fmt) exit(70); if(!(fmt=strdup(orig_fmt))) return 0; for(i=0;fmt[i];i++) { if(fmt[i] == '%') { i++; switch(fmt[i]) { - case '~':case 'p':case 'n':case 'h':case 'u':case 'f':case 's':case 'm':case '%'://when adding new format things add here and... + case '~':case 'p':case 'n':case 'h':case 'u':case 'f':case 's': + case 'm':case '%':case '0':case '1':case '2':case '3':case '4': + case '5':case '6':case '7':case '8':case '9'://when adding new format things add here and... c++; } } @@ -191,7 +213,9 @@ char *format_magic(int fd,char *from,struct user *user,char *orig_fmt,char *arg) if(fmt[i] == '%') { i++; switch(fmt[i]) { - case '~':case 'p':case 'n':case 'h':case 'u':case 'f':case 's':case 'm':case '%'://here. + case '~':case 'p':case 'n':case 'h':case 'u':case 'f':case 's': + case 'm':case '%':case '0':case '1':case '2':case '3':case '4': + case '5':case '6':case '7':case '8':case '9'://here. args[c]=((fmt[i]=='n')?user->nick: ((fmt[i]=='u')?user->user: ((fmt[i]=='~')?getcwd(seghome,SEGHOMELEN): @@ -199,10 +223,21 @@ char *format_magic(int fd,char *from,struct user *user,char *orig_fmt,char *arg) ((fmt[i]=='f')?from: ((fmt[i]=='p')?pid: ((fmt[i]=='m')?myuser->nick://and here. - ((fmt[i]=='s')?arg:"%" - )))))))); + ((fmt[i]=='s')?arg: + ((fmt[i]=='0')?argN[0]: + ((fmt[i]=='1')?argN[1]: + ((fmt[i]=='2')?argN[2]: + ((fmt[i]=='3')?argN[3]: + /* I bet */ ((fmt[i]=='4')?argN[4]: + /* you */ ((fmt[i]=='5')?argN[5]: + /* hate */ ((fmt[i]=='6')?argN[6]: + /* this, */ ((fmt[i]=='7')?argN[7]: + /* dontcha? :)*/ ((fmt[i]=='8')?argN[8]: + ((fmt[i]=='9')?argN[9]:"%" + )))))))))))))))))); fmt[i-1]=0; - notargs[c]=strdup(fmt+j); + if(!(fmt+j)) exit(68); + if(!(notargs[c]=strdup(fmt+j))) exit(66); sz+=strlen(args[c]); sz+=strlen(notargs[c]); c++; @@ -210,7 +245,8 @@ char *format_magic(int fd,char *from,struct user *user,char *orig_fmt,char *arg) } } } - notargs[c]=strdup(fmt+j); + if(!(fmt+j)) exit(69); + if(!(notargs[c]=strdup(fmt+j))) exit(67); sz+=strlen(notargs[c]); output=malloc(sz+1); output[0]=0; @@ -221,6 +257,7 @@ char *format_magic(int fd,char *from,struct user *user,char *orig_fmt,char *arg) strcat(output,notargs[i]); output[sz]=0; free(fmt); + free(argCopy); return output; } @@ -240,6 +277,7 @@ void eofp(FILE *fp) { } //this function got scary. basically handles all the tail magic. +//feature creature void extra_handler(int fd) { int tmpo,i; static int mmerp=0; @@ -250,15 +288,16 @@ void extra_handler(int fd) { } else { lines_sent=0; } + oldtime=time(0);//this might fix it? if(redirect_to_fd != -1) { fd=redirect_to_fd; } - for(i=0;i_> + if(tailf[i].lines != -1) {//if the tail isn't locked due to spam limit. + if(fgets(tmp,BS-1,tailf[i].fp) == NULL) {//if there isn't anything to read right now... if(tailf[i].lines != 0 && (tailf[i].opt & TAILO_ENDMSG)) { privmsg(fd,tailf[i].to,"---------- TAILO_ENDMSG border ----------"); } @@ -280,7 +319,7 @@ void extra_handler(int fd) { //privmsg(fd,tailf[i].to,tmp2); tailf[i].lines=0; } - else { + else {//if there was something to read. tailf[i].lines++; mmerp=0; if(strchr(tmp,'\r')) *strchr(tmp,'\r')=0; @@ -289,6 +328,7 @@ void extra_handler(int fd) { if(tailf[i].opt & TAILO_FORMAT) { tmp2=format_magic(fd,tailf[i].to,tailf[i].user,tmp,tailf[i].args); } else { + if(!tmp) exit(72); tmp2=strdup(tmp); } message_handler(fd,tailf[i].to,tailf[i].user,tmp2,0); @@ -315,19 +355,11 @@ void extra_handler(int fd) { } } -void file_tail(int fd,char *from,char *file,char *args,char opt,struct user *user) { +void file_tail(int fd,char *from,char *file,char *args,int opt,struct user *user) { int i; int fdd; char tmp[256]; struct stat st; - for(i=0;i= currentmaxtails) { currentmaxtails=i+1;} if(!(tailf[i].fp=fdopen(fdd,"r"))) { snprintf(tmp,sizeof(tmp),"file_tail: failed to fdopen(%s)\n",file); privmsg(fd,from,tmp); } else { - fcntl(fileno(tailf[i].fp),F_SETFL,O_NONBLOCK); + fcntl(fdd,F_SETFL,O_NONBLOCK); if(!(opt & TAILO_BEGIN)) { eofp(tailf[i].fp); } + if(!from) exit(73); tailf[i].to=strdup(from); if(!tailf[i].to) { mywrite(fd,"QUIT :malloc error 3!!!\r\n"); return; } + if(!file) exit(74); tailf[i].file=strdup(file); if(!tailf[i].file) { mywrite(fd,"QUIT :malloc error 4!!!\r\n"); @@ -395,17 +430,36 @@ void file_tail(int fd,char *from,char *file,char *args,char opt,struct user *use void c_botup(int fd,char *from,...) { char tmp[256]; - snprintf(tmp,sizeof(tmp)-1,"botup: %lu",(unsigned long int)time(0)-start_time); + snprintf(tmp,sizeof(tmp)-1,"botup: %llu",time(0)-start_time); privmsg(fd,from,tmp); } void c_leettail(int fd,char *from,char *file,struct user *user,...) { - short a=file[0]-'0'; - short b=file[1]-'0'; - short c=file[2]-'0'; - short d; - short n; - if(file[2] >= '0' && file[2] <= '9') { + int a; + int b; + int c; + int d; + int n; + if(!file) { + privmsg(fd,from,"!leettail NNfilename"); + privmsg(fd,from,"!leettail NNNfilename"); + privmsg(fd,from,"!leettail NN#channel:filename"); + privmsg(fd,from,"!leettail NNN#channel:filename"); + return; + } + if(file[0]) { + if(file[1]) { + if(file[2]) { + // + }else { + privmsg(fd,from,"usage1: !leettail NN filename"); + privmsg(fd,from,"usage2: !leettail NNN filename"); + return; + }}} + a=file[0]-'0'; + b=file[1]-'0'; + c=file[2]-'0'; + if(c >= 0 && c <= 9) { d=(a*100)+(b*10)+(c); n=3; } else { @@ -428,8 +482,10 @@ void c_changetail(int fd,char *from,char *line,struct user *user,...) { int i; int fdd; char *mode=0; - //if(line == 0) return mywrite(fd,"QUIT :line == 0 in changetail\r\n"); - //if(from == 0) return mywrite(fd,"QUIT :from == 0 in changetail\r\n"); + if(!line) { + privmsg(fd,from,"usage: !changetail filename target tailmode"); + return; + } if((merp=strchr(line,' '))) { *merp=0; merp++; @@ -444,16 +500,17 @@ void c_changetail(int fd,char *from,char *line,struct user *user,...) { return; } if(debug) { - snprintf(tmp,sizeof(tmp)-1,"changetail opened file '%s' with fd: %d / %d\n",line,fdd,maxtails); + snprintf(tmp,sizeof(tmp)-1,"changetail opened file '%s' with fd: %d / %d / %d\n",line,fdd,currentmaxtails,maxtails); privmsg(fd,"#cmd",tmp); } fstat(fdd,&st); close(fdd); - for(i=0;itarget); } + if(!derp) exit(77); ht_setkey(&alias,line,strdup(derp)); } void c_kill(int fd,char *from,char *line,...) { + if(!line) { + privmsg(fd,from,"usage: !kill signum pid"); + return; + } char *csig=line; char *cpid=strchr(line,' '); int sig,pid; @@ -618,84 +691,76 @@ void c_id(int fd,char *from,...) { privmsg(fd,from,tmp); } +//fix this fucking shit. void c_leetuntail(int fd,char *from,char *line,...) { + if(!line) { + privmsg(fd,from,"usage: !leetuntail [target|*] filename"); + return; + } char *frm=line; - char *file=0; - int frmN=0; + char *file; int i; - char tmp[512]; if((file=strchr(line,' '))) { *file=0; file++; + } else { + file=line; + frm="."; } if(file) { - if(*frm == '*') { - for(i=0;i IRCdestination"); - for(i=0;inick); + if(!msg) exit(78); myuser->nick=strdup(msg); irc_nick(fd,myuser->nick); } @@ -896,16 +983,16 @@ void c_nick(int fd,char *from,char *msg,...) { void message_handler(int fd,char *from,struct user *user,char *msg,int redones) { struct entry *m; union hack lol; + char lambdad; char *command; + char *oldcommand; char *args; -// char *magic; char tmp[512]; int len; int sz; //debug_time(fd,from); if(user->nick) { if(strcmp(user->nick,myuser->nick)) { - if(locked_down) return; for(sz=0;shitlist[sz];sz++) { if(!strcmp(shitlist[sz],user->nick)) { return; @@ -936,33 +1023,32 @@ void message_handler(int fd,char *from,struct user *user,char *msg,int redones) //if(*msg != '!') { // return; //} - - command=strdup(msg); - if(command[0] == trigger_char) { + if(!msg) exit(71); + oldcommand=strdup(msg); + command=oldcommand; + if(*command == trigger_char) { command++; } else { + free(oldcommand); return; } - //privmsg(fd,from,command); if((args=strchr(command,' '))) { *args=0; args++; } - //if(!strncmp(command,"lambda",6)) { - // command+=8; - // if((args=strchr(command,' '))) { - // *args=0; - // args++; - // } - // args=format_magic(fd,from,user,args,":/"); - //} + if(!strncmp(command,"lambda",6)) { + command+=8; + if((args=strchr(command,' '))) { + *args=0; + args++; + } + args=format_magic(fd,from,user,args,":/"); + lambdad=1; + } if((lol.data=ht_getvalue(&builtin,command))) { func=lol.func; - // privmsg(fd,from,"found it in builtins HT."); func(fd,from,args,user); - //if(args != (command + strlen(command) + 2)) { - // free(args); - //} + if(lambdad) {free(args);} } else if(redones < 5) { debug_time(fd,from,"checking aliases..."); @@ -973,6 +1059,7 @@ void message_handler(int fd,char *from,struct user *user,char *msg,int redones) message_handler(fd,from,user,redo,redones+1); free(redo); redo=0; + free(oldcommand); return; } debug_time(fd,from,"finished checking aliases. not found."); @@ -985,10 +1072,12 @@ void message_handler(int fd,char *from,struct user *user,char *msg,int redones) if(redones >5) { privmsg(fd,from,"I don't know if I'll ever get out of this alias hole you're telling me to dig. Fuck this."); } + free(oldcommand); } void line_handler(int fd,char *line) {//this should be built into the libary? char *s=line,*t=0,*u=0; + char tmp[512]; struct user *user=malloc(sizeof(struct user)); user->nick=0; user->user=0; @@ -1053,9 +1142,21 @@ void line_handler(int fd,char *line) {//this should be built into the libary? myuser->nick[strlen(myuser->nick)-1]=(rand()%10)+'0'; irc_nick(fd,myuser->nick); } - if(!strcmp(s,"004")) {//we're connected. + else if(!strcmp(s,"004")) {//we're connected. startup_stuff(fd); } +//:armitage.hacking.allowed.org 353 asdf = #default :@SegFault @FreeArtMan @foobaz @wall @Lamb3_13 @gizmore @blackh0le + strcpy(tmp,"!"); + strcat(tmp,s); + if(ht_getnode(&alias,tmp) != NULL) { //don't bother to do a WHOLE message handler if the alias doesn't exist. + snprintf(tmp,sizeof(tmp),"!%s %s",s,u); + message_handler(fd,"#cmd",user,tmp,0); + } +/* +:armitage.hacking.allowed.org 376 asdf :End of MOTD commandWHO #default +:armitage.hacking.allowed.org 352 asdf #default user hostname server nick H@ :0 name +:armitage.hacking.allowed.org 315 asdf #default :End of WHO list +*/ } if(s && t && u) { if(!strcmp(s,"PRIVMSG") && strcmp(user->nick,myuser->nick)) { @@ -1083,6 +1184,7 @@ void line_handler(int fd,char *line) {//this should be built into the libary? if(!strcmp(s,"NICK")) { if(!strcmp(user->nick,myuser->nick)) { free(myuser->nick); + if(!t+1) exit(79); myuser->nick=strdup(t+1); } } @@ -1107,6 +1209,7 @@ int main(int argc,char *argv[]) { BUILDIN("linelimit",c_linelimit); BUILDIN("nick",c_nick); BUILDIN("tailunlock",c_tailunlock); + BUILDIN("istaillocked",c_istaillocked); BUILDIN("changetail",c_changetail); BUILDIN("tails",c_tails); BUILDIN("record",c_record); @@ -1114,17 +1217,17 @@ int main(int argc,char *argv[]) { BUILDIN("leettail",c_leettail); BUILDIN("leetuntail",c_leetuntail); BUILDIN("leetappend",c_leetappend); - BUILDIN("untail",c_untail); BUILDIN("say",c_say); BUILDIN("id",c_id); BUILDIN("kill",c_kill); BUILDIN("alias",c_alias_h); BUILDIN("aliases",c_aliases_h); + BUILDIN("lobotomy",c_lobotomy); + BUILDIN("amnesia",c_amnesia); mode_magic=0; trigger_char='!'; redirect_to_fd=-1; debug=0; - locked_down=(argc>2); lines_sent=0; line_limit=25; recording=0; @@ -1137,12 +1240,12 @@ int main(int argc,char *argv[]) { exit(0); } else { maxtails=nofile.rlim_max; + currentmaxtails=4; tailf=malloc(sizeof(struct tail) * (maxtails + 1)); } myuser=malloc(sizeof(struct user)); myuser->nick=strdup(argc>1?argv[1]:NICK); - myuser->user="I_dunno"; - myuser->host="I_dunno"; + myuser->host="I_dunno";//??? snprintf(pid,6,"%d",getpid()); printf("starting segfault...\n"); if(!getuid() || !geteuid()) { @@ -1157,7 +1260,8 @@ int main(int argc,char *argv[]) { printf("going to run segfault as user %s\n",pwd->pw_name); if(!pwd) { printf("well, shit. I don't know who I am."); return 0; } } - for(c=0;cuser=strdup(pwd->pw_name); + for(c=0;c