summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorepoch <epoch@hacking.allowed.org>2014-02-09 06:27:44 -0600
committerepoch <epoch@hacking.allowed.org>2014-02-09 06:27:44 -0600
commit2bf21d6516ed44567e9cf842b25fc30a3affc03f (patch)
tree327d5a9bf3ec02a43a4ceb73117bbf4870cc968e
parent8ea60384731c92fe1daa64160f6cacc33177066d (diff)
downloadsegfault-2bf21d6516ed44567e9cf842b25fc30a3affc03f.tar.gz
segfault-2bf21d6516ed44567e9cf842b25fc30a3affc03f.zip
upgraded format_magic() to hopefully be more compatible and less voodoo-y.
-rwxr-xr-xsegfaultbin26258 -> 26200 bytes
-rw-r--r--segfault.c63
-rw-r--r--testing.c65
3 files changed, 62 insertions, 66 deletions
diff --git a/segfault b/segfault
index 4a18bb0..a94eb6d 100755
--- a/segfault
+++ b/segfault
Binary files differ
diff --git a/segfault.c b/segfault.c
index f3721b4..b98973c 100644
--- a/segfault.c
+++ b/segfault.c
@@ -112,6 +112,67 @@ void message_handler(int fd,char *from,char *nick,char *msg,int redones);
void c_untail(int fd,char *from, char *file);
char *format_magic(int fd,char *from,char *nick,char *orig_fmt,char *arg) {
+ int i,j;
+ int sz=0,c=1;
+ char *output;
+ char *fmt=strdup(orig_fmt);
+ char **args,**notargs;
+ for(i=0;fmt[i];i++) {
+ if(fmt[i] == '%') {
+ i++;
+ switch(fmt[i]) {
+ case 'u':
+ case 'f':
+ case 's':
+ c++;
+ }
+ }
+ }
+ args=malloc((sizeof(char *)) * (c + 1));
+ notargs=malloc((sizeof(char *)) * (c + 2));
+ c=0;
+ for(j=0,i=0;fmt[i];i++) {
+ if(fmt[i] == '%') {
+ i++;
+ switch(fmt[i]) {
+ case 'u':
+ args[c]=nick;
+ break;
+ case 'f':
+ args[c]=from;
+ break;
+ case 's':
+ args[c]=arg;
+ break;
+ }
+ switch(fmt[i]) {
+ case 'u':
+ case 'f':
+ case 's':
+ fmt[i-1]=0;
+ notargs[c]=strdup(fmt+j);
+ sz+=strlen(args[c]);
+ sz+=strlen(notargs[c]);
+ c++;
+ i++;
+ j=i;
+ break;
+ }
+ }
+ }
+ notargs[c]=strdup(fmt+j);
+ sz+=strlen(notargs[c]);
+ output=malloc(sz+1);
+ for(i=0;i<c;i++) {
+ strcat(output,notargs[i]);
+ strcat(output,args[i]);
+ }
+ strcat(output,notargs[i]);
+ free(fmt);
+ return output;
+}
+/*
+char *format_magic(int fd,char *from,char *nick,char *orig_fmt,char *arg) {
int i;
int c=1;
char *fmt=strdup(orig_fmt);
@@ -167,7 +228,7 @@ char *format_magic(int fd,char *from,char *nick,char *orig_fmt,char *arg) {
free(fmt);
return output;
}
-
+*/
//get rid of this?
char *good_format_string(int fd,char *from,char *line) {
int i;
diff --git a/testing.c b/testing.c
deleted file mode 100644
index 63c2620..0000000
--- a/testing.c
+++ /dev/null
@@ -1,65 +0,0 @@
-#include <stdio.h>
-
-char *format_magic(char *from,char *nick,char *fmt,char *arg);
-
-int main(int argc,char *argv[]) {
- char *o=format_magic("#default","epoch",argv[1],argv[2]);
- printf("%s\n",o);
- return 0;
-}
-
-char *format_magic(char *from,char *nick,char *fmt,char *arg) {
- int i;
- int j;
- int c=1;
- for(i=0;fmt[i];i++) {
- if(fmt[i] == '%') {
- i++;
- switch(fmt[i]) {
- case 0:
- printf("error! last character is a '%'!!!\n");
- exit(1);
- case 'u':
- case 'f':
- case 's':
- c++;
- }
- }
- }
- char **args=malloc((sizeof(char *)) * (c + 1));
- c=0;
- for(i=0;fmt[i];i++) {
- if(fmt[i] == '%') {
- i++;
- switch(fmt[i]) {
- case 0:
- printf("error! last character is a '%'!!!\n");
- exit(1);
- case 'u':
- args[c]=nick;
- fmt[i]='s';
- c++;
- break;
- case 'f':
- args[c]=from;
- fmt[i]='s';
- c++;
- break;
- case 's':
- args[c]=arg;
- c++;
- break;
- }
- }
- }
-// args[c]=0;
-// for(i=0;i<c;i++) {
-// printf("args[%d]=%s\n",i,args[i]);
-// }
-// printf("format string: %s\nc: %d\n",fmt,c);
- int sz=vprintf(fmt,args)+1;
-// printf("\nsize: %d\n",sz);
- char *output=malloc(sz);
- vsnprintf(output,sz,fmt,args);
- return output;
-}