Przeglądaj źródła

Merge branch 'fix-constness'

* fix-constness:
  * Fix const char* issues
  * Don't use heap for the ghost_write return buffer
Bryan Drewery 16 lat temu
rodzic
commit
398a82c36a
6 zmienionych plików z 23 dodań i 21 usunięć
  1. 6 5
      src/enclink.c
  2. 2 2
      src/enclink.h
  3. 10 9
      src/net.c
  4. 3 3
      src/net.h
  5. 1 1
      src/userrec.c
  6. 1 1
      src/userrec.h

+ 6 - 5
src/enclink.c

@@ -130,9 +130,10 @@ static int ghost_read(int snum, char *src, size_t *len)
   return OK;
 }
 
-static char *ghost_write(int snum, char *src, size_t *len)
+static const char *ghost_write(int snum, const char *src, size_t *len)
 {
-  char *srcbuf = NULL, *buf = NULL, *line = NULL, *eol = NULL, *eline = NULL;
+  static char buf[SGRAB + 14] = "";
+  char *srcbuf = NULL, *line = NULL, *eol = NULL, *eline = NULL;
   size_t bufpos = 0;
 
   const size_t bufsiz = *len + 9 + 1;
@@ -153,7 +154,7 @@ static char *ghost_write(int snum, char *src, size_t *len)
       if (!socklist[snum].oseed)
         socklist[snum].oseed++;
     }
-    buf = (char *) my_realloc(buf, bufpos + strlen(eline) + 1 + 9);
+//    buf = (char *) my_realloc(buf, bufpos + strlen(eline) + 1 + 9);
     strcpy((char *) &buf[bufpos], eline);
     free(eline);
     strcat(buf, "\n");
@@ -172,7 +173,7 @@ static char *ghost_write(int snum, char *src, size_t *len)
       if (!socklist[snum].oseed)
         socklist[snum].oseed++;
     }
-    buf = (char *) my_realloc(buf, bufpos + strlen(eline) + 1 + 9);
+//    buf = (char *) my_realloc(buf, bufpos + strlen(eline) + 1 + 9);
     strcpy((char *) &buf[bufpos], eline);
     free(eline);
     strcat(buf, "\n");
@@ -264,7 +265,7 @@ int link_read(int snum, char *buf, size_t *len)
   return -1;
 }
 
-char *link_write(int snum, char *buf, size_t *len)
+const char *link_write(int snum, const char *buf, size_t *len)
 {
   int i = socklist[snum].enclink;
 

+ 2 - 2
src/enclink.h

@@ -27,7 +27,7 @@ struct enc_link {
   const char *name;
   int type;
   void (*link) (int, direction_t);
-  char *(*write) (int, char *, size_t *);
+  const char *(*write) (int, const char *, size_t *);
   int (*read) (int, char *, size_t *);
   void (*parse) (int, int, char *);
 };
@@ -43,7 +43,7 @@ extern struct enc_link enclink[];
 extern int link_find_by_type(int);
 
 extern void link_link(int, int, int, direction_t);
-extern char *link_write(int, char *, size_t *);
+extern const char *link_write(int, const char *, size_t *);
 extern int link_read(int, char *, size_t *);
 extern void link_hash(int, char *);
 extern void link_send(int, const char *, ...) __attribute__((format(printf, 2, 3)));

+ 10 - 9
src/net.c

@@ -393,10 +393,10 @@ void setsock(int sock, int options)
 }
 
 #ifdef USE_IPV6
-int real_getsock(int options, int af_def, char *fname, int line)
+int real_getsock(int options, int af_def, const char *fname, int line)
 {
 #else
-int real_getsock(int options, char *fname, int line)
+int real_getsock(int options, const char *fname, int line)
 {
   int af_def = AF_INET;
 #endif /* USE_IPV6 */
@@ -1228,7 +1228,7 @@ int sockgets(char *s, int *len)
  * 
  * NOTE: Do NOT put Contexts in here if you want DEBUG to be meaningful!!
  */
-void tputs(register int z, char *s, size_t len)
+void tputs(register int z, const char *s, size_t len)
 {
   if (z < 0)			/* um... HELLO?!  sanity check please! */
     return;			
@@ -1274,8 +1274,8 @@ void tputs(register int z, char *s, size_t len)
 	memcpy(p + socklist[i].outbuflen, s, len);
 	socklist[i].outbuf = p;
 	socklist[i].outbuflen += len;
-        if (socklist[i].encstatus && s)
-          free(s);
+//        if (socklist[i].encstatus && s)
+//          free(s);
 	return;
       }
       /* Try. */
@@ -1298,8 +1298,8 @@ void tputs(register int z, char *s, size_t len)
 	memcpy(socklist[i].outbuf, &s[x], len - x);
 	socklist[i].outbuflen = len - x;
       }
-      if (socklist[i].encstatus && s)
-        free(s);
+//      if (socklist[i].encstatus && s)
+//        free(s);
       return;
     }
   }
@@ -1312,8 +1312,9 @@ void tputs(register int z, char *s, size_t len)
 
     putlog(LOG_MISC, "*", "!!! writing to nonexistent socket: %d", z);
     if (strlen(s)) {
-      s[strlen(s) - 1] = 0;
-      putlog(LOG_MISC, "*", "!-> '%s'", s);
+      char *tmp = strdup(s); /* To null-terminate */
+      putlog(LOG_MISC, "*", "!-> '%s'", tmp);
+      free(tmp);
     }
 
     inhere = 0;

+ 3 - 3
src/net.h

@@ -104,10 +104,10 @@ int allocsock(int, int);
 
 #ifdef USE_IPV6
 #define getsock(opt, af) real_getsock(opt, af, __FILE__, __LINE__)
-int real_getsock(int, int, char *, int);
+int real_getsock(int, int, const char *, int);
 #else
 #define getsock(opt) real_getsock(opt, __FILE__, __LINE__)
-int real_getsock(int, char *, int);
+int real_getsock(int, const char *, int);
 #endif /* USE_IPV6 */
 
 
@@ -125,7 +125,7 @@ int open_address_listen(in_addr_t, port_t *);
 int open_telnet(const char *, port_t, bool proxy = 0, int identd = 0);
 int open_telnet_dcc(int, char *, char *);
 int open_telnet_raw(int, const char *, port_t, bool, int = 0);
-void tputs(int, char *, size_t);
+void tputs(int, const char *, size_t);
 void dequeue_sockets();
 int sockgets(char *, int *);
 void tell_netdebug(int);

+ 1 - 1
src/userrec.c

@@ -323,7 +323,7 @@ void convert_password(struct userrec *u)
 /* Try: pass_match_by_host("-",host)
  * will return 1 if no password is set for that host
  */
-int u_pass_match(struct userrec *u, char *in)
+int u_pass_match(struct userrec *u, const char *in)
 {
   if (!u)
     return 0;

+ 1 - 1
src/userrec.h

@@ -9,7 +9,7 @@ struct userrec *adduser(struct userrec *, char *, char *, char *, flag_t, int);
 void addhost_by_handle(char *, char *);
 void clear_masks(struct maskrec *);
 void clear_userlist(struct userrec *);
-int u_pass_match(struct userrec *, char *);
+int u_pass_match(struct userrec *, const char *);
 int delhost_by_handle(char *, char *);
 int count_users(struct userrec *);
 int deluser(char *);