From: Art Cancro Date: Sat, 15 Jun 2002 20:34:39 +0000 (+0000) Subject: * Use safestrncpy() instead of strncpy() where appropriate X-Git-Tag: v7.86~6371 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=b2a695cd70bcbcd0da7985eecadea400253eee3c;p=citadel.git * Use safestrncpy() instead of strncpy() where appropriate * Fixed a memory allocation bug in the vCard parser --- diff --git a/webcit/ChangeLog b/webcit/ChangeLog index 5a6d027af..847f34c2c 100644 --- a/webcit/ChangeLog +++ b/webcit/ChangeLog @@ -1,4 +1,8 @@ $Log$ +Revision 323.39 2002/06/15 20:34:39 ajc +* Use safestrncpy() instead of strncpy() where appropriate +* Fixed a memory allocation bug in the vCard parser + Revision 323.38 2002/05/23 03:40:05 ajc * Brought over a utility function I'll need later @@ -831,4 +835,3 @@ Sun Dec 6 19:50:55 EST 1998 Art Cancro 1998-12-03 Nathan Bryant * webserver.c: warning fix - diff --git a/webcit/locate_host.c b/webcit/locate_host.c index 68715d49f..fce39363a 100644 --- a/webcit/locate_host.c +++ b/webcit/locate_host.c @@ -50,6 +50,6 @@ void locate_host(char *tbuf, int client_socket) sprintf(tbuf, "%d.%d.%d.%d", a1, a2, a3, a4); return; } - strncpy(tbuf, ch->h_name, 64); + safestrncpy(tbuf, ch->h_name, 64); tbuf[63] = 0; } diff --git a/webcit/messages.c b/webcit/messages.c index 198cc4b58..d70184a2e 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -69,11 +69,10 @@ char buf[]; end = pos; } - strncpy(urlbuf, &buf[start], end - start); + safestrncpy(urlbuf, &buf[start], end - start); urlbuf[end - start] = 0; - - strncpy(outbuf, buf, start); + safestrncpy(outbuf, buf, start); sprintf(&outbuf[start], "%cA HREF=%c%s%c TARGET=%c%s%c%c%s%c/A%c", LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB); strcat(outbuf, &buf[end]); diff --git a/webcit/snprintf.c b/webcit/snprintf.c index 7db792c20..7c8f2b92c 100644 --- a/webcit/snprintf.c +++ b/webcit/snprintf.c @@ -57,7 +57,7 @@ int vsnprintf(char *buf, size_t max, const char *fmt, va_list argp) if ((size = vsprintf(p, fmt, argp)) >= max) size = -1; - strncpy(buf, p, max); + safestrncpy(buf, p, max); buf[max - 1] = 0; free(p); return size; diff --git a/webcit/subst.c b/webcit/subst.c index 095e414a1..f5014eb50 100644 --- a/webcit/subst.c +++ b/webcit/subst.c @@ -183,7 +183,7 @@ void do_template(void *templatename) { strcpy(inbuf, ""); } else { - strncpy(outbuf, inbuf, pos); + safestrncpy(outbuf, inbuf, pos); outbuf[pos] = 0; wprintf("%s", outbuf); strcpy(inbuf, &inbuf[pos]); @@ -191,7 +191,7 @@ void do_template(void *templatename) { for (i=strlen(inbuf); i>=0; --i) { if (inbuf[i]=='>') pos = i; } - strncpy(key, &inbuf[2], pos-2); + safestrncpy(key, &inbuf[2], pos-2); key[pos-2] = 0; print_value_of(key); strcpy(inbuf, &inbuf[pos+1]); diff --git a/webcit/tcp_sockets.c b/webcit/tcp_sockets.c index 9c32b7158..bb20bbd2f 100644 --- a/webcit/tcp_sockets.c +++ b/webcit/tcp_sockets.c @@ -54,7 +54,7 @@ int uds_connectsock(char *sockpath) memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; - strncpy(addr.sun_path, sockpath, sizeof addr.sun_path); + safestrncpy(addr.sun_path, sockpath, sizeof addr.sun_path); s = socket(AF_UNIX, SOCK_STREAM, 0); if (s < 0) { diff --git a/webcit/vcard.c b/webcit/vcard.c index 362dbe6b6..6b0421595 100644 --- a/webcit/vcard.c +++ b/webcit/vcard.c @@ -89,12 +89,12 @@ struct vCard *vcard_load(char *vtext) { colonpos = pattern2(ptr, ":"); nlpos = pattern2(ptr, "\n"); - if (nlpos > colonpos > 0) { + if ((nlpos > colonpos) && (colonpos > 0)) { namebuf = malloc(colonpos + 1); valuebuf = malloc(nlpos - colonpos + 1); - strncpy(namebuf, ptr, colonpos); + safestrncpy(namebuf, ptr, colonpos); namebuf[colonpos] = 0; - strncpy(valuebuf, &ptr[colonpos+1], nlpos-colonpos-1); + safestrncpy(valuebuf, &ptr[colonpos+1], nlpos-colonpos-1); valuebuf[nlpos-colonpos-1] = 0; if ( (!strcasecmp(namebuf, "end")) diff --git a/webcit/webcit.c b/webcit/webcit.c index bbd183813..fb222755c 100644 --- a/webcit/webcit.c +++ b/webcit/webcit.c @@ -74,7 +74,7 @@ void addurls(char *url) while (strlen(up) > 0) { /* locate the = sign */ - strncpy(buf, up, 255); + safestrncpy(buf, up, sizeof buf); b = (-1); for (a = 255; a >= 0; --a) if (buf[a] == '=') diff --git a/webcit/webcit.h b/webcit/webcit.h index f8cb1e5ed..516aff864 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -308,3 +308,4 @@ void get_preference(char *key, char *value); void set_preference(char *key, char *value); void knrooms(void); int is_msg_in_mset(char *mset, long msgnum); +char *safestrncpy(char *dest, const char *src, size_t n);