From: <al...@us...> - 2003-04-04 20:12:41
|
Update of /cvsroot/msyslog/syslog/src/modules In directory sc8-pr-cvs1:/tmp/cvs-serv5529/modules Modified Files: om_classic.c Log Message: proper string mgmt, even from config other assumed size prev defined, but this way is less error prone Index: om_classic.c =================================================================== RCS file: /cvsroot/msyslog/syslog/src/modules/om_classic.c,v retrieving revision 1.92 retrieving revision 1.93 diff -u -d -r1.92 -r1.93 --- om_classic.c 6 Jan 2003 23:17:39 -0000 1.92 +++ om_classic.c 4 Apr 2003 20:12:37 -0000 1.93 @@ -341,7 +341,7 @@ strncpy(c->f_un.f_forw.f_hname, ++p, sizeof(c->f_un.f_forw.f_hname) - 1); - c->f_un.f_forw.f_hname[sizeof(c->f_un.f_forw.f_hname) - 1] + c->f_un.f_forw.f_hname[sizeof (c->f_un.f_forw.f_hname) - 1] = '\0'; if ((sa = resolv_name(c->f_un.f_forw.f_hname, "syslog", "udp", @@ -363,8 +363,8 @@ p++; case '|': /* from sysklogd */ case '/': - strncpy(c->f_un.f_fname, p, sizeof c->f_un.f_fname); - c->f_un.f_fname[sizeof (c->f_un.f_fname) - 1] = 0; + strncpy(c->f_un.f_fname, p, sizeof (c->f_un.f_fname) - 1); + c->f_un.f_fname[sizeof (c->f_un.f_fname) - 1] = '\0'; if ( *p == '|' ) { if (global->flist_des) { @@ -410,9 +410,13 @@ default: for (i = 0; i < MAXUNAMES && *p; i++) { + for (q = p; *q && *q != ','; ) q++; - (void)strncpy(c->f_un.f_uname[i], p, UT_NAMESIZE); + + strncpy(c->f_un.f_uname[i], p, sizeof (c->f_un.f_uname[0]) - 1); + c->f_un.f_uname[i][sizeof (c->f_un.f_uname[0]) - 1] = '\0'; + if ((q - p) > UT_NAMESIZE) c->f_un.f_uname[i][UT_NAMESIZE] = '\0'; else @@ -496,8 +500,9 @@ #endif continue; - strncpy(line, ut.ut_line, sizeof(ut.ut_line)); - line[sizeof(ut.ut_line)] = '\0'; + strncpy(line, ut.ut_line, sizeof (line) - 1); + line[sizeof (line) - 1] = '\0'; + if (c->f_type == F_WALL) { if ((p = ttymsg(iov, 6, line, TTYMSGTIME)) != NULL) { errno = 0; /* already in msg */ @@ -506,6 +511,7 @@ } continue; } + /* should we send the message to this user? */ for (i = 0; i < MAXUNAMES; i++) { if (!c->f_un.f_uname[i][0]) |