Commits

alone committed 36b4a4a

Fix several memory leaks reported by valgrind.
Fix a posible buffer overflow in add_year func.

Comments (0)

Files changed (3)

     unsigned long i;
     int fdin, fdout,s;
     s_list list;
-    s_word word;
+    s_word aux, * word = &aux;
     s_opts options ={ FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, {'\0'}}; 
 
     //word = (s_word*)amalloc(sizeof(s_word));
     }
 
     if (options.has_word){
-        word.word= input;
-        word.size= strlen(input);
-        list_add_item(&list, &word);
+        word->word= input;
+        word->size= strlen(input);
+        list_add_item(&list, word);
     }
     else if(options.has_file){
         if((fdin=open(input, O_RDONLY)) == -1)
             exit(-1);
         }
 
-        while((s=read_word(fdin, &word)) !=0){
-            list_add_item(&list, &word);
-            free(word.word);
+        while((s=read_word(fdin, word)) !=0){
+            list_add_item(&list, word);
+            free(word->word);
         }
 
         close(fdin);
 
     mutator(&options, &list);
 
-    word = *(list.first);
+    word = list.first;
     for (i=0;i<list.count;i++)
     {
-        write_word(fdout, &word);        
-        word = *(word.next);
+        write_word(fdout, word);        
+        word = word->next;
     }
 
     list_destroy(&list);
 
     aux = list->first;
     list->first = list->first->next;
+    free(aux->word);
     free(aux);
 
     list->count--;
     printf("\t[-] Append year mutations generated: ");
     for(j=0;j<list->count;j++)
     {
-        if(waux->size < WORDSIZE)
+        if((waux->size+strlen(buf)) < WORDSIZE)
         {
             sprintf(dest->word,"%s%s\n",waux->word,buf);
             dest->size = strlen(waux->word)+strlen(buf);