From bedd7ddf6bb0e7b735282ea22d57aedef45edc40 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Sun, 13 Jan 2008 16:57:43 +0000 Subject: [PATCH] * avoid some function calls openBSD doesn't like us to use. (like sprintf) fancily this evades one error valgrind was always complaining about. --- citadel/citserver.c | 68 ++++++++++++++++++++++++++++----------------- citadel/sysdep.c | 2 +- citadel/user_ops.c | 5 ++-- 3 files changed, 46 insertions(+), 29 deletions(-) diff --git a/citadel/citserver.c b/citadel/citserver.c index d09599ad3..37a3f7280 100644 --- a/citadel/citserver.c +++ b/citadel/citserver.c @@ -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], ""); } diff --git a/citadel/sysdep.c b/citadel/sysdep.c index 7bc8741c7..92308d948 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -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); diff --git a/citadel/user_ops.c b/citadel/user_ops.c index 36b749f45..f87045d3f 100644 --- a/citadel/user_ops.c +++ b/citadel/user_ops.c @@ -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"); } -- 2.39.2