Segfault prevention
authorNeutron Soutmun <neo.neutron@gmail.com>
Fri, 22 Aug 2008 04:42:47 +0000 (11:42 +0700)
committerNeutron Soutmun <neo.neutron@gmail.com>
Sun, 2 Nov 2008 19:43:11 +0000 (02:43 +0700)
2008-08-22  Neutron Soutmun <neo.neutron@gmail.com>

* src/rahunasd.c, src/rh-xmlrpc-server.c:
  - Rename dummy to termstring (make sense).
  - More preventing the segfault due to print NULL string pointer.

ChangeLog
src/rahunasd.c
src/rh-xmlrpc-server.c

index f612168..8ab5e7a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2008-08-22  Neutron Soutmun <neo.neutron@gmail.com>
+
+       * src/rahunasd.c, src/rh-xmlrpc-server.c:
+         - Rename dummy to termstring (make sense).
+         - More preventing the segfault due to print NULL string pointer.
+
 2008-08-21  Neutron Soutmun <neo.neutron@gmail.com>
 
        * src/rahunasd.{h,c}, src/rh-xmlrpc-server.c:
index 8838d92..4d27c4b 100644 (file)
@@ -43,7 +43,7 @@ struct set *rahunas_set = NULL;
 struct set **set_list = NULL;
 ip_set_id_t max_sets = 0;
 
-const char *dummy = '\0';
+const char *termstring = '\0';
 pid_t pid, sid;
 
 uint32_t iptoid(struct rahunas_map *map, const char *ip) {
@@ -72,7 +72,10 @@ char *idtoip(struct rahunas_map *map, uint32_t id) {
   struct in_addr sess_addr;
 
   if (!map)
-         return NULL;
+    return termstring;
+
+  if (id < 0)
+    return termstring;
 
   sess_addr.s_addr = htonl((ntohl(map->first_ip) + id));
 
@@ -105,15 +108,15 @@ void rh_free(void **data)
 
 void rh_free_member (struct rahunas_member *member)
 {
-  if (member->username && member->username != dummy)
+  if (member->username && member->username != termstring)
     free(member->username);
 
-  if (member->session_id && member->session_id != dummy)
+  if (member->session_id && member->session_id != termstring)
     free(member->session_id);
   
   memset(member, 0, sizeof(struct rahunas_member));
-  member->username = dummy;
-  member->session_id = dummy;
+  member->username = termstring;
+  member->session_id = termstring;
 }
 
 int rh_openlog(const char *filename)
@@ -453,10 +456,10 @@ size_t expired_check(void *data)
                            send_xmlrpc_stopacct(map, i);
 
           if (!members[i].username)
-            members[i].username = dummy;
+            members[i].username = termstring;
 
           if (!members[i].session_id)
-            members[i].session_id = dummy;
+            members[i].session_id = termstring;
 
           logmsg(RH_LOG_NORMAL, "Session Idle-Timeout, User: %s, IP: %s, "
                                 "Session ID: %s, MAC: %s",
index 92b082b..b812b13 100644 (file)
@@ -11,7 +11,7 @@
 #include "rh-ipset.h"
 
 extern struct set *rahunas_set;
-extern const char* dummy;
+extern const char* termstring;
 
 int do_startsession(GNetXmlRpcServer *server,
                     const gchar *command,
@@ -79,19 +79,19 @@ int do_startsession(GNetXmlRpcServer *server,
   res = set_adtip(rahunas_set, ip, mac_address, IP_SET_OP_ADD_IP);
   if (res == 0) {
     members[id].flags = 1;
-    if (members[id].username && members[id].username != dummy)
+    if (members[id].username && members[id].username != termstring)
       free(members[id].username);
 
-    if (members[id].session_id && members[id].username != dummy)
+    if (members[id].session_id && members[id].username != termstring)
       free(members[id].session_id);
 
     members[id].username   = strdup(username);
     if (!members[id].username)
-      members[id].username = dummy;
+      members[id].username = termstring;
 
     members[id].session_id = strdup(session_id);
     if (!members[id].session_id)
-      members[id].session_id = dummy;
+      members[id].session_id = termstring;
 
                time(&(members[id].session_start));
 
@@ -179,10 +179,10 @@ int do_stopsession(GNetXmlRpcServer *server,
                       IP_SET_OP_DEL_IP);
       if (res == 0) {
         if (!members[id].username)
-          members[id].username = dummy;
+          members[id].username = termstring;
 
         if (!members[id].session_id)
-          members[id].session_id = dummy;
+          members[id].session_id = termstring;
 
         logmsg(RH_LOG_NORMAL, "Session Stop, User: %s, IP: %s, "
                               "Session ID: %s, MAC: %s",