* avoid some function calls openBSD doesn't like us to use. (like sprintf) fancily...
authorWilfried Göesgens <willi@citadel.org>
Sun, 13 Jan 2008 16:57:43 +0000 (16:57 +0000)
committerWilfried Göesgens <willi@citadel.org>
Sun, 13 Jan 2008 16:57:43 +0000 (16:57 +0000)
citadel/citserver.c
citadel/sysdep.c
citadel/user_ops.c

index d09599ad363dc4c1d2d4b8b1b2edccb0cff607e3..37a3f7280c16fb48f6dbd9074a24188633be9faf 100644 (file)
@@ -360,11 +360,16 @@ int is_public_client(void)
        char addrbuf[1024];
        FILE *fp;
        int i;
+       char *public_clientspos;
+       char *public_clientsend;
+       char *paddr = NULL;
        struct stat statbuf;
        static time_t pc_timestamp = 0;
        static char public_clients[SIZ];
        static char public_clients_file[SIZ];
 
+#define LOCALHOSTSTR "127.0.0.1"
+
        snprintf(public_clients_file, 
                         sizeof public_clients_file,
                         "%s/public_clients",
@@ -387,36 +392,45 @@ int is_public_client(void)
                begin_critical_section(S_PUBLIC_CLIENTS);
                lprintf(CTDL_INFO, "Loading %s\n", public_clients_file);
 
-               safestrncpy(public_clients, "127.0.0.1", sizeof public_clients);
+               public_clientspos = &public_clients[0];
+               public_clientsend = public_clientspos + SIZ;
+               safestrncpy(public_clientspos, LOCALHOSTSTR, sizeof public_clients);
+               public_clientspos += sizeof(LOCALHOSTSTR) - 1;
+               
                if (hostname_to_dotted_quad(addrbuf, config.c_fqdn) == 0) {
-                       strcat(public_clients, "|");
-                       strcat(public_clients, addrbuf);
+                       *(public_clientspos++) = '|';
+                       paddr = &addrbuf[0];
+                       while (!IsEmptyStr (paddr) && 
+                              (public_clientspos < public_clientsend))
+                               *(public_clientspos++) = *(paddr++);
                }
 
                fp = fopen(public_clients_file, "r");
-               if (fp != NULL) while (fgets(buf, sizeof buf, fp)!=NULL) {
-                       char *ptr;
-                       ptr = buf;
-                       while (!IsEmptyStr(ptr)) {
-                               if (*ptr == '#') {
-                                       *ptr = 0;
-                                       break;
-                               }
+               if (fp != NULL) 
+                       while ((fgets(buf, sizeof buf, fp)!=NULL) &&
+                              (public_clientspos < public_clientsend)){
+                               char *ptr;
+                               ptr = buf;
+                               while (!IsEmptyStr(ptr)) {
+                                       if (*ptr == '#') {
+                                               *ptr = 0;
+                                               break;
+                                       }
                                else ptr++;
-                       }
-                       ptr--;
-                       while (ptr>buf && isspace(*ptr)) {
-                               *(ptr--) = 0;
-                       }
-                       if (hostname_to_dotted_quad(addrbuf, buf) == 0) {
-                               if ((strlen(public_clients) +
-                                  strlen(addrbuf) + 2)
-                                  < sizeof(public_clients)) {
-                                       strcat(public_clients, "|");
-                                       strcat(public_clients, addrbuf);
+                               }
+                               ptr--;
+                               while (ptr>buf && isspace(*ptr)) {
+                                       *(ptr--) = 0;
+                               }
+                               if (hostname_to_dotted_quad(addrbuf, buf) == 0) {
+                                       *(public_clientspos++) = '|';
+                                       paddr = addrbuf;
+                                       while (!IsEmptyStr(paddr) && 
+                                              (public_clientspos < public_clientsend)){
+                                               *(public_clientspos++) = *(paddr++);
+                                       }
                                }
                        }
-               }
                fclose(fp);
                pc_timestamp = time(NULL);
                end_critical_section(S_PUBLIC_CLIENTS);
@@ -643,6 +657,7 @@ void GenerateRoomDisplay(char *real_room,
                        struct CitContext *viewer) {
 
        int ra;
+       int rlen;
 
        strcpy(real_room, viewed->room.QRname);
        if (viewed->room.QRflags & QR_MAILBOX) {
@@ -656,9 +671,10 @@ void GenerateRoomDisplay(char *real_room,
        }
 
        if (viewed->cs_flags & CS_CHAT) {
-               while (strlen(real_room) < 14)
-                       strcat(real_room, " ");
-
+               rlen = strlen(real_room);
+               while (rlen < 14)
+                       real_room[rlen] = ' ';
+               real_room[15] = '\0';
                strcpy(&real_room[14], "<chat>");
        }
 
index 7bc8741c7d886fc994684b21cae46f806f6d9d12..92308d948e3813f4f64a53d8358c4d8042546b96 100644 (file)
@@ -155,7 +155,7 @@ void vlprintf(enum LogLevel loglevel, const char *format, va_list arg_ptr)
                                tim.tm_mday, tim.tm_hour, tim.tm_min,
                                tim.tm_sec, (long)tv.tv_usec);
                }
-               vsprintf(buf2, format, arg_ptr);   
+               vsnprintf(buf2, SIZ, format, arg_ptr);   
 
                fprintf(stderr, "%s%s", buf, buf2);
                fflush(stderr);
index 36b749f451b70c604749afd61aa3b2252f77de14..f87045d3f76782edfd5a3378e3962afe29a9be4c 100644 (file)
@@ -1657,8 +1657,9 @@ void cmd_asup(char *cmdbuf)
        }
 
        if (deleted) {
-               sprintf(notify, "User \"%s\" has been deleted by %s.\n",
-                       usbuf.fullname, CC->user.fullname);
+               snprintf(notify, SIZ, 
+                        "User \"%s\" has been deleted by %s.\n",
+                        usbuf.fullname, CC->user.fullname);
                aide_message(notify, "User Deletion Message");
        }