Explorar el Código

* Port [3408] to 1.2.14
* Fix more portability issues with sizeof() operator



svn: 3409

Bryan Drewery hace 19 años
padre
commit
468db03d54
Se han modificado 3 ficheros con 12 adiciones y 14 borrados
  1. 5 8
      src/enclink.c
  2. 2 4
      src/net.c
  3. 5 2
      src/net.h

+ 5 - 8
src/enclink.c

@@ -19,18 +19,15 @@ static void ghost_link_case(int idx, direction_t direction)
     char initkey[33] = "", *tmp2 = NULL;
     char tmp[70] = "";
     char *keyp = NULL, *nick1 = NULL, *nick2 = NULL;
-    size_t key_len = 0;
     port_t port = 0;
 
     if (direction == TO) {
       keyp = socklist[snum].ikey;
-      key_len = sizeof(socklist[snum].ikey);
       nick1 = strdup(dcc[idx].nick);
       nick2 = strdup(conf.bot->nick);
       port = htons(dcc[idx].port);
     } else if (direction == FROM) {
       keyp = socklist[snum].okey;
-      key_len = sizeof(socklist[snum].okey);
       nick1 = strdup(conf.bot->nick);
       nick2 = strdup(dcc[idx].nick);
 
@@ -47,7 +44,7 @@ static void ghost_link_case(int idx, direction_t direction)
     sprintf(tmp, "%s@%4x@%s@%s", settings.bdhash, port, strtoupper(nick1), strtoupper(nick2));
     free(nick1);
     free(nick2);
-    strlcpy(keyp, SHA1(tmp), key_len);
+    strlcpy(keyp, SHA1(tmp), ENC_KEY_LEN + 1);
 #ifdef DEBUG
     putlog(LOG_DEBUG, "@", "Link hash for %s: %s", dcc[idx].nick, tmp);
     putlog(LOG_DEBUG, "@", "outkey (%d): %s", strlen(keyp), keyp);
@@ -66,8 +63,8 @@ static void ghost_link_case(int idx, direction_t direction)
 
       link_send(idx, "elink %s %d\n", tmp2, socklist[snum].oseed);
       free(tmp2);
-      strcpy(socklist[snum].okey, initkey);
-      strcpy(socklist[snum].ikey, initkey);
+      strlcpy(socklist[snum].okey, initkey, ENC_KEY_LEN + 1);
+      strlcpy(socklist[snum].ikey, initkey, ENC_KEY_LEN + 1);
     } else {
       socklist[snum].encstatus = 1;
       socklist[snum].gz = 1;
@@ -170,8 +167,8 @@ void ghost_parse(int idx, int snum, char *buf)
   if (!egg_strcasecmp(code, "elink")) {
     char *tmp = decrypt_string(settings.salt2, newsplit(&buf));
 
-    strlcpy(socklist[snum].okey, tmp, sizeof(socklist[snum].okey));
-    strlcpy(socklist[snum].ikey, socklist[snum].okey, sizeof(socklist[snum].ikey));
+    strlcpy(socklist[snum].okey, tmp, ENC_KEY_LEN + 1);
+    strlcpy(socklist[snum].ikey, socklist[snum].okey, ENC_KEY_LEN + 1);
     socklist[snum].iseed = atoi(buf);
     socklist[snum].oseed = atoi(buf);
     putlog(LOG_BOTS, "*", "Handshake with %s succeeded, we're linked.", dcc[idx].nick);

+ 2 - 4
src/net.c

@@ -413,10 +413,8 @@ int allocsock(int sock, int options)
       socklist[i].encstatus = 0;
       socklist[i].enclink = -1;
       socklist[i].gz = 0;
-      egg_bzero(&socklist[i].okey, sizeof(socklist[i].okey));
-      egg_bzero(&socklist[i].ikey, sizeof(socklist[i].ikey));
-      socklist[i].okey[0] = 0;
-      socklist[i].ikey[0] = 0;
+      egg_bzero(&(socklist[i].okey), ENC_KEY_LEN + 1);
+      egg_bzero(&(socklist[i].ikey), ENC_KEY_LEN + 1);
       socks_total++;
       sdprintf("allocsock(%d) = %d", i, sock);
       return i;

+ 5 - 2
src/net.h

@@ -11,6 +11,9 @@
 #include <setjmp.h>
 
 
+#define ENC_KEY_LEN 32
+
+
 #ifdef HAVE_OPENSSL_SSL_H
 # ifdef USE_SSL
 #  include <openssl/ssl.h>
@@ -98,8 +101,8 @@ typedef struct {
   char *host;
   port_t port;
   short          flags;
-  char okey[33];                        /* botlink enckey: out */
-  char ikey[33];                        /* botlink enckey: in  */
+  char okey[ENC_KEY_LEN + 1];                        /* botlink enckey: out */
+  char ikey[ENC_KEY_LEN + 1];                        /* botlink enckey: in  */
 } sock_list;