summary refs log tree commit diff stats
path: root/plugins/fishlim
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/fishlim')
-rw-r--r--plugins/fishlim/Makefile.am2
-rw-r--r--plugins/fishlim/fish.c10
-rw-r--r--plugins/fishlim/fish.h2
-rw-r--r--plugins/fishlim/fishlim.vcxproj2
-rw-r--r--plugins/fishlim/fishlim.vcxproj.filters6
-rw-r--r--plugins/fishlim/irc.h2
-rw-r--r--plugins/fishlim/keystore.c13
-rw-r--r--plugins/fishlim/keystore.h4
-rw-r--r--plugins/fishlim/misc.c54
-rw-r--r--plugins/fishlim/misc.h36
-rw-r--r--plugins/fishlim/plugin_hexchat.c8
-rw-r--r--plugins/fishlim/test.c4
12 files changed, 19 insertions, 124 deletions
diff --git a/plugins/fishlim/Makefile.am b/plugins/fishlim/Makefile.am
index c57a4de9..df541396 100644
--- a/plugins/fishlim/Makefile.am
+++ b/plugins/fishlim/Makefile.am
@@ -3,7 +3,7 @@ EXTRA_DIST = INSTALL LICENSE
 libdir = $(hexchatlibdir)
 
 lib_LTLIBRARIES = fishlim.la
-fishlim_la_SOURCES = fish.c irc.c keystore.c misc.c plugin_hexchat.c
+fishlim_la_SOURCES = fish.c irc.c keystore.c plugin_hexchat.c
 fishlim_la_LDFLAGS = $(PLUGIN_LDFLAGS) -module
 fishlim_la_LIBADD = $(GLIB_LIBS) $(OPENSSL_LIBS)
 fishlim_la_CFLAGS = $(GLIB_CFLAGS) $(OPENSSL_CFLAGS) -I$(top_srcdir)/src/common
diff --git a/plugins/fishlim/fish.c b/plugins/fishlim/fish.c
index 93420f23..a230185d 100644
--- a/plugins/fishlim/fish.c
+++ b/plugins/fishlim/fish.c
@@ -75,9 +75,8 @@ char *fish_encrypt(const char *key, size_t keylen, const char *message) {
     
     messagelen = strlen(message);
     if (messagelen == 0) return NULL;
-    encrypted = malloc(((messagelen-1)/8)*12 + 12 + 1); // each 8-byte block becomes 12 bytes
+    encrypted = g_malloc(((messagelen - 1) / 8) * 12 + 12 + 1); // each 8-byte block becomes 12 bytes
     end = encrypted;
-    if (!encrypted) return NULL;
      
     while (*message) {
         // Read 8 bytes (a Blowfish block)
@@ -124,9 +123,8 @@ char *fish_decrypt(const char *key, size_t keylen, const char *data) {
     unsigned char d;
     BF_set_key(&bfkey, keylen, (const unsigned char*)key);
     
-    decrypted = malloc(strlen(data)+1);
+    decrypted = g_malloc(strlen(data) + 1);
     end = decrypted;
-    if (!decrypted) return NULL;
     
     while (*data) {
         // Convert from FiSH-BASE64
@@ -172,7 +170,7 @@ char *fish_encrypt_for_nick(const char *nick, const char *data) {
     // Encrypt
     encrypted = fish_encrypt(key, strlen(key), data);
     
-    free(key);
+    g_free(key);
     return encrypted;
 }
 
@@ -190,7 +188,7 @@ char *fish_decrypt_from_nick(const char *nick, const char *data) {
     // Decrypt
     decrypted = fish_decrypt(key, strlen(key), data);
     
-    free(key);
+    g_free(key);
     return decrypted;
 }
 
diff --git a/plugins/fishlim/fish.h b/plugins/fishlim/fish.h
index db471326..d7415a5a 100644
--- a/plugins/fishlim/fish.h
+++ b/plugins/fishlim/fish.h
@@ -28,6 +28,8 @@
 #include <stdbool.h>
 #include <stddef.h>
 
+#include <glib.h>
+
 char *fish_encrypt(const char *key, size_t keylen, const char *message);
 char *fish_decrypt(const char *key, size_t keylen, const char *data);
 char *fish_encrypt_for_nick(const char *nick, const char *data);
diff --git a/plugins/fishlim/fishlim.vcxproj b/plugins/fishlim/fishlim.vcxproj
index f1eb95ba..ca3de578 100644
--- a/plugins/fishlim/fishlim.vcxproj
+++ b/plugins/fishlim/fishlim.vcxproj
@@ -103,14 +103,12 @@
     <ClInclude Include="fish.h" />

     <ClInclude Include="irc.h" />

     <ClInclude Include="keystore.h" />

-    <ClInclude Include="misc.h" />

     <ClInclude Include="plugin_hexchat.h" />

   </ItemGroup>

   <ItemGroup>

     <ClCompile Include="fish.c" />

     <ClCompile Include="irc.c" />

     <ClCompile Include="keystore.c" />

-    <ClCompile Include="misc.c" />

     <ClCompile Include="plugin_hexchat.c" />

   </ItemGroup>

   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

diff --git a/plugins/fishlim/fishlim.vcxproj.filters b/plugins/fishlim/fishlim.vcxproj.filters
index 7c13733b..d8fbf454 100644
--- a/plugins/fishlim/fishlim.vcxproj.filters
+++ b/plugins/fishlim/fishlim.vcxproj.filters
@@ -32,9 +32,6 @@
     <ClInclude Include="keystore.h">

       <Filter>Header Files</Filter>

     </ClInclude>

-    <ClInclude Include="misc.h">

-      <Filter>Header Files</Filter>

-    </ClInclude>

     <ClInclude Include="plugin_hexchat.h">

       <Filter>Header Files</Filter>

     </ClInclude>

@@ -49,9 +46,6 @@
     <ClCompile Include="keystore.c">

       <Filter>Source Files</Filter>

     </ClCompile>

-    <ClCompile Include="misc.c">

-      <Filter>Source Files</Filter>

-    </ClCompile>

     <ClCompile Include="plugin_hexchat.c">

       <Filter>Source Files</Filter>

     </ClCompile>

diff --git a/plugins/fishlim/irc.h b/plugins/fishlim/irc.h
index dc43185c..7ff72355 100644
--- a/plugins/fishlim/irc.h
+++ b/plugins/fishlim/irc.h
@@ -28,6 +28,8 @@
 #include <stdbool.h>
 #include <stddef.h>
 
+#include <glib.h>
+
 bool irc_parse_message(const char *words[],
                        const char **prefix, const char **command,
                        size_t *parameters_offset);
diff --git a/plugins/fishlim/keystore.c b/plugins/fishlim/keystore.c
index caad3628..964b4cb4 100644
--- a/plugins/fishlim/keystore.c
+++ b/plugins/fishlim/keystore.c
@@ -29,7 +29,6 @@
 #include <string.h>
 #include "irc.h"
 #include "fish.h"
-#include "misc.h"
 #include "keystore.h"
 #include "plugin_hexchat.h"
 
@@ -97,7 +96,7 @@ char *keystore_get_key(const char *nick) {
     
     if (strncmp(value, "+OK ", 4) != 0) {
         // Key is stored in plaintext
-        return import_glib_string(value);
+        return value;
     } else {
         // Key is encrypted
         const char *encrypted = value+4;
@@ -191,7 +190,7 @@ bool keystore_store_key(const char *nick, const char *key) {
         
         // Store encrypted in file
         g_key_file_set_string(keyfile, nick, "key", wrapped);
-        free(wrapped);
+        g_free(wrapped);
     } else {
         // Store unencrypted in file
         g_key_file_set_string(keyfile, nick, "key", key);
@@ -220,11 +219,3 @@ bool keystore_delete_nick(const char *nick) {
     g_key_file_free(keyfile);
     return ok;
 }
-
-
-void keystore_secure_free(void *ptr, size_t size) {
-    secure_erase(ptr, size);
-    free(ptr);
-}
-
-
diff --git a/plugins/fishlim/keystore.h b/plugins/fishlim/keystore.h
index a2c33f02..3c609867 100644
--- a/plugins/fishlim/keystore.h
+++ b/plugins/fishlim/keystore.h
@@ -28,11 +28,11 @@
 #include <stdbool.h>
 #include <stddef.h>
 
+#include <glib.h>
+
 char *keystore_get_key(const char *nick);
 bool keystore_store_key(const char *nick, const char *key);
 bool keystore_delete_nick(const char *nick);
 
-void keystore_secure_free(void *ptr, size_t size);
-
 #endif
 
diff --git a/plugins/fishlim/misc.c b/plugins/fishlim/misc.c
deleted file mode 100644
index 2b78961d..00000000
--- a/plugins/fishlim/misc.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
-
-  Copyright (c) 2010 Samuel Lidén Borell <samuel@kodafritt.se>
-
-  Permission is hereby granted, free of charge, to any person obtaining a copy
-  of this software and associated documentation files (the "Software"), to deal
-  in the Software without restriction, including without limitation the rights
-  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-  copies of the Software, and to permit persons to whom the Software is
-  furnished to do so, subject to the following conditions:
-
-  The above copyright notice and this permission notice shall be included in
-  all copies or substantial portions of the Software.
-
-  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-  THE SOFTWARE.
-
-*/
-
-#include <glib.h>
-#include <stdlib.h>
-#include <string.h>
-#include "misc.h"
-
-
-void secure_erase(void *ptr, size_t size) {
-    // "volatile" prevents this code from being optimized away
-    volatile char* volptr = ptr;
-    while (size--) *volptr++ = 0;
-}
-
-/**
- * Re-allocates a string with the native allocator.
- */
-char *import_glib_string(gchar *gstr) {
-    size_t size;
-    char *native;
-    if (g_mem_is_system_malloc()) return gstr;
-    
-    size = strlen(gstr)+1;
-    native = malloc(size);
-    memcpy(native, gstr, size);
-    
-    secure_erase(gstr, size);
-    g_free(gstr);
-    return native;
-}
-
-
diff --git a/plugins/fishlim/misc.h b/plugins/fishlim/misc.h
deleted file mode 100644
index ee4fc5b8..00000000
--- a/plugins/fishlim/misc.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
-
-  Copyright (c) 2010 Samuel Lidén Borell <samuel@kodafritt.se>
-
-  Permission is hereby granted, free of charge, to any person obtaining a copy
-  of this software and associated documentation files (the "Software"), to deal
-  in the Software without restriction, including without limitation the rights
-  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-  copies of the Software, and to permit persons to whom the Software is
-  furnished to do so, subject to the following conditions:
-
-  The above copyright notice and this permission notice shall be included in
-  all copies or substantial portions of the Software.
-
-  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-  THE SOFTWARE.
-
-*/
-
-#ifndef MISC_H
-#define MISC_H
-
-void secure_erase(void *ptr, size_t size);
-
-#ifdef __G_LIB_H__
-char *import_glib_string(gchar *gstr);
-#endif
-
-#endif
-
-
diff --git a/plugins/fishlim/plugin_hexchat.c b/plugins/fishlim/plugin_hexchat.c
index 67866021..82befceb 100644
--- a/plugins/fishlim/plugin_hexchat.c
+++ b/plugins/fishlim/plugin_hexchat.c
@@ -93,7 +93,7 @@ static int handle_outgoing(char *word[], char *word_eol[], void *userdata) {
     // Send message
     hexchat_commandf(ph, "PRIVMSG %s :+OK %s", channel, encrypted);
     
-    free(encrypted);
+    g_free(encrypted);
     return HEXCHAT_EAT_HEXCHAT;
 }
 
@@ -180,7 +180,7 @@ static int handle_incoming(char *word[], char *word_eol[], hexchat_event_attrs *
 
         g_string_append (message, peice);
     }
-    free(decrypted);
+    g_free(decrypted);
     
     // Simulate unencrypted message
     //hexchat_printf(ph, "simulating: %s\n", message->str);
@@ -191,8 +191,8 @@ static int handle_incoming(char *word[], char *word_eol[], hexchat_event_attrs *
     return HEXCHAT_EAT_HEXCHAT;
   
   decrypt_error:
-    free(decrypted);
-    free(sender_nick);
+    g_free(decrypted);
+    g_free(sender_nick);
     return HEXCHAT_EAT_NONE;
 }
 
diff --git a/plugins/fishlim/test.c b/plugins/fishlim/test.c
index b4dc8d91..91a9ede1 100644
--- a/plugins/fishlim/test.c
+++ b/plugins/fishlim/test.c
@@ -47,7 +47,7 @@ static int decrypt(int nick_count, char *nicks[]) {
         return 1;
       success:
         fprintf(stderr, "Decrypted text >>>%s<<<\n", msg);
-        free(msg);
+        g_free(msg);
     }
     return 0;
 }
@@ -64,7 +64,7 @@ static int encrypt(int nick_count, char *nicks[]) {
             char *encrypted = fish_encrypt_for_nick(nicks[i], message);
             if (encrypted) {
                 fprintf(stderr, "Encrypted [%s]:  >>>%s<<<\n", nicks[i], encrypted);
-                free(encrypted);
+                g_free(encrypted);
             } else {
                 error = true;
             }