diff options
-rw-r--r-- | usr.sbin/apmd/contrib/pccardq.c | 6 | ||||
-rw-r--r-- | usr.sbin/diskcheckd/diskcheckd.c | 7 | ||||
-rw-r--r-- | usr.sbin/faithd/ftp.c | 78 | ||||
-rw-r--r-- | usr.sbin/pkg_install/add/extract.c | 6 | ||||
-rw-r--r-- | usr.sbin/pkg_install/create/pl.c | 4 | ||||
-rw-r--r-- | usr.sbin/pw/grupd.c | 2 | ||||
-rw-r--r-- | usr.sbin/pw/pw_conf.c | 4 | ||||
-rw-r--r-- | usr.sbin/pw/pwupd.c | 2 | ||||
-rw-r--r-- | usr.sbin/syslogd/syslogd.c | 7 |
9 files changed, 62 insertions, 54 deletions
diff --git a/usr.sbin/apmd/contrib/pccardq.c b/usr.sbin/apmd/contrib/pccardq.c index 2bace22..1c551a1 100644 --- a/usr.sbin/apmd/contrib/pccardq.c +++ b/usr.sbin/apmd/contrib/pccardq.c @@ -164,7 +164,11 @@ get_slot_info(int so, int slot, char **manuf, char **version, char char *_version; char *_device; - slen = snprintf(buf, sizeof buf, "N%d", slot); + if ((slen = snprintf(buf, sizeof buf, "N%d", slot)) == -1) { + warnc(0, "write"); + goto err; + } + if ((rv = write(so, buf, slen)) < 0) { warn("write"); goto err; diff --git a/usr.sbin/diskcheckd/diskcheckd.c b/usr.sbin/diskcheckd/diskcheckd.c index 558b583..cb79a08 100644 --- a/usr.sbin/diskcheckd/diskcheckd.c +++ b/usr.sbin/diskcheckd/diskcheckd.c @@ -443,8 +443,9 @@ updateproctitle(struct disk *disks) { p += sizeof _PATH_DEV - 1; percent = 100 * (double)dseek(dp, 0, SEEK_CUR) / dp->size; - if ((size_t)(ret = snprintf(bp, size, - "%s %.2f%%, ", p, percent)) >= size) { + if ((ret = snprintf(bp, size, "%s %.2f%%, ", p, percent)) == -1) + ret = 0; + if ((size_t)ret >= size) { inc = ((ret + 1023) >> 10) << 10; size += inc; bufsize += inc; @@ -456,6 +457,8 @@ updateproctitle(struct disk *disks) { } bp = buf + bufsize - size; ret = snprintf(bp, size, "%s %.2f%%, ", p, percent); + if (ret == -1) + ret = 0; } bp += ret; size -= ret; diff --git a/usr.sbin/faithd/ftp.c b/usr.sbin/faithd/ftp.c index b0daa5a..037453e 100644 --- a/usr.sbin/faithd/ftp.c +++ b/usr.sbin/faithd/ftp.c @@ -410,8 +410,7 @@ ftp_copyresult(int src, int dst, enum state state) "425 Cannot open data connetion\r\n"); } } - write(dst, rbuf, n); - return n; + return n > 0 ? write(dst, rbuf, n) : n; case LPRT: case EPRT: /* expecting "200 PORT command successful." */ @@ -505,8 +504,7 @@ passivefail0: passivefail: n = snprintf(sbuf, sizeof(sbuf), "500 could not translate from PASV\r\n"); - write(src, sbuf, n); - return n; + return n > 0 ? write(src, sbuf, n) : n; } #ifdef IPV6_FAITH { @@ -566,14 +564,16 @@ passivefail: UC(a[8]), UC(a[9]), UC(a[10]), UC(a[11]), UC(a[12]), UC(a[13]), UC(a[14]), UC(a[15]), 2, UC(p[0]), UC(p[1])); - write(dst, sbuf, n); + if (n > 0) + n = write(dst, sbuf, n); passivemode = 1; return n; } else { n = snprintf(sbuf, sizeof(sbuf), "229 Entering Extended Passive Mode (|||%d|)\r\n", ntohs(sin6->sin6_port)); - write(dst, sbuf, n); + if (n > 0) + n = write(dst, sbuf, n); passivemode = 1; return n; } @@ -626,8 +626,7 @@ passivefail1: passivefail2: n = snprintf(sbuf, sizeof(sbuf), "500 could not translate from EPSV\r\n"); - write(src, sbuf, n); - return n; + return n > 0 ? write(src, sbuf, n) : n; } #ifdef IP_FAITH { @@ -684,7 +683,8 @@ passivefail2: "227 Entering Passive Mode (%d,%d,%d,%d,%d,%d)\r\n", UC(a[0]), UC(a[1]), UC(a[2]), UC(a[3]), UC(p[0]), UC(p[1])); - write(dst, sbuf, n); + if (n > 0) + n = write(dst, sbuf, n); passivemode = 1; return n; } @@ -786,8 +786,7 @@ ftp_copycommand(int src, int dst, enum state *state) if (epsvall) { n = snprintf(sbuf, sizeof(sbuf), "501 %s disallowed in EPSV ALL\r\n", cmd); - write(src, sbuf, n); - return n; + return n > 0 ? write(src, sbuf, n) : n; } n = sscanf(param, @@ -800,8 +799,7 @@ ftp_copycommand(int src, int dst, enum state *state) if (n != 21 || af != 6 || hal != 16|| pal != 2) { n = snprintf(sbuf, sizeof(sbuf), "501 illegal parameter to LPRT\r\n"); - write(src, sbuf, n); - return n; + return n > 0 ? write(src, sbuf, n) : n; } /* keep LPRT parameter */ @@ -821,8 +819,7 @@ sendport: lprtfail: n = snprintf(sbuf, sizeof(sbuf), "500 could not translate to PORT\r\n"); - write(src, sbuf, n); - return n; + return n > 0 ? write(src, sbuf, n) : n; } if (((struct sockaddr *)&data4)->sa_family != AF_INET) goto lprtfail; @@ -863,7 +860,8 @@ lprtfail: n = snprintf(sbuf, sizeof(sbuf), "PORT %d,%d,%d,%d,%d,%d\r\n", UC(a[0]), UC(a[1]), UC(a[2]), UC(a[3]), UC(p[0]), UC(p[1])); - write(dst, sbuf, n); + if (n > 0) + n = write(dst, sbuf, n); *state = nstate; passivemode = 0; return n; @@ -885,8 +883,7 @@ lprtfail: if (epsvall) { n = snprintf(sbuf, sizeof(sbuf), "501 %s disallowed in EPSV ALL\r\n", cmd); - write(src, sbuf, n); - return n; + return n > 0 ? write(src, sbuf, n) : n; } p = param; @@ -898,8 +895,7 @@ lprtfail: eprtparamfail: n = snprintf(sbuf, sizeof(sbuf), "501 illegal parameter to EPRT\r\n"); - write(src, sbuf, n); - return n; + return n > 0 ? write(src, sbuf, n) : n; } *p++ = '\0'; hostp = p; @@ -919,8 +915,7 @@ eprtparamfail: if (n != 1 || af != 2) { n = snprintf(sbuf, sizeof(sbuf), "501 unsupported address family to EPRT\r\n"); - write(src, sbuf, n); - return n; + return n > 0 ? write(src, sbuf, n) : n; } memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; @@ -929,14 +924,12 @@ eprtparamfail: if (error) { n = snprintf(sbuf, sizeof(sbuf), "501 EPRT: %s\r\n", gai_strerror(error)); - write(src, sbuf, n); - return n; + return n > 0 ? write(src, sbuf, n) : n; } if (res->ai_next) { n = snprintf(sbuf, sizeof(sbuf), "501 EPRT: %s resolved to multiple addresses\r\n", hostp); - write(src, sbuf, n); - return n; + return n > 0 ? write(src, sbuf, n) : n; } memcpy(&data6, res->ai_addr, res->ai_addrlen); @@ -957,13 +950,13 @@ eprtparamfail: if (epsvall) { n = snprintf(sbuf, sizeof(sbuf), "501 %s disallowed in EPSV ALL\r\n", cmd); - write(src, sbuf, n); - return n; + return n > 0 ? write(src, sbuf, n) : n; } /* transmit PASV */ n = snprintf(sbuf, sizeof(sbuf), "PASV\r\n"); - write(dst, sbuf, n); + if (n > 0) + n = write(dst, sbuf, n); *state = LPSV; passivemode = 0; /* to be set to 1 later */ return n; @@ -978,7 +971,8 @@ eprtparamfail: wport4 = wport6 = port4 = port6 = -1; n = snprintf(sbuf, sizeof(sbuf), "PASV\r\n"); - write(dst, sbuf, n); + if (n > 0) + n = write(dst, sbuf, n); *state = EPSV; passivemode = 0; /* to be set to 1 later */ return n; @@ -989,8 +983,7 @@ eprtparamfail: */ epsvall = 1; n = snprintf(sbuf, sizeof(sbuf), "200 EPSV ALL command successful.\r\n"); - write(src, sbuf, n); - return n; + return n > 0 ? write(src, sbuf, n) : n; #ifdef FAITH4 } else if (strcmp(cmd, "PORT") == 0 && param) { /* @@ -1012,8 +1005,7 @@ eprtparamfail: if (n != 6) { n = snprintf(sbuf, sizeof(sbuf), "501 illegal parameter to PORT\r\n"); - write(src, sbuf, n); - return n; + return n > 0 ? write(src, sbuf, n) : n; } memset(&data6, 0, sizeof(data6)); @@ -1032,8 +1024,7 @@ eprtparamfail: portfail: n = snprintf(sbuf, sizeof(sbuf), "500 could not translate to EPRT\r\n"); - write(src, sbuf, n); - return n; + return n > 0 ? write(src, sbuf, n) : n; } if (((struct sockaddr *)&data4)->sa_family != AF_INET6) goto portfail; @@ -1073,7 +1064,8 @@ portfail: goto portfail; } n = snprintf(sbuf, sizeof(sbuf), "EPRT |%d|%s|%s|\r\n", af, host, serv); - write(dst, sbuf, n); + if (n > 0) + n = write(dst, sbuf, n); *state = nstate; passivemode = 0; return n; @@ -1092,7 +1084,8 @@ portfail: /* transmit EPSV */ n = snprintf(sbuf, sizeof(sbuf), "EPSV\r\n"); - write(dst, sbuf, n); + if (n > 0) + n = write(dst, sbuf, n); *state = PASV; passivemode = 0; /* to be set to 1 later */ return n; @@ -1102,8 +1095,7 @@ portfail: * reject PORT/PASV */ n = snprintf(sbuf, sizeof(sbuf), "502 %s not implemented.\r\n", cmd); - write(src, sbuf, n); - return n; + return n > 0 ? write(src, sbuf, n) : n; #endif /* FAITH4 */ } else if (passivemode && (strcmp(cmd, "STOR") == 0 @@ -1119,7 +1111,8 @@ portfail: if (ftp_passiveconn() < 0) { n = snprintf(sbuf, sizeof(sbuf), "425 Cannot open data connetion\r\n"); - write(src, sbuf, n); + if (n > 0) + n = write(src, sbuf, n); } else { /* simply relay the command */ write(dst, rbuf, n); @@ -1130,8 +1123,7 @@ portfail: } else { /* simply relay it */ *state = NONE; - write(dst, rbuf, n); - return n; + return write(dst, rbuf, n); } bad: diff --git a/usr.sbin/pkg_install/add/extract.c b/usr.sbin/pkg_install/add/extract.c index f331c03..534b9ca 100644 --- a/usr.sbin/pkg_install/add/extract.c +++ b/usr.sbin/pkg_install/add/extract.c @@ -158,7 +158,7 @@ extract_plist(char *home, Package *pkg) PUSHOUT(Directory); } add_count = snprintf(&perm_args[perm_count], maxargs - perm_count, "'%s' ", p->name); - if (add_count > maxargs - perm_count) { + if (add_count == -1 || add_count > maxargs - perm_count) { cleanup(0); errx(2, __FUNCTION__ ": oops, miscounted strings!"); } @@ -178,7 +178,7 @@ extract_plist(char *home, Package *pkg) PUSHOUT(Directory); } add_count = snprintf(&where_args[where_count], maxargs - where_count, " '%s'", p->name); - if (add_count > maxargs - where_count) { + if (add_count == -1 || add_count > maxargs - where_count) { cleanup(0); errx(2, __FUNCTION__ ": oops, miscounted strings!"); } @@ -186,7 +186,7 @@ extract_plist(char *home, Package *pkg) add_count = snprintf(&perm_args[perm_count], maxargs - perm_count, "'%s' ", p->name); - if (add_count > maxargs - perm_count) { + if (add_count == -1 || add_count > maxargs - perm_count) { cleanup(0); errx(2, __FUNCTION__ ": oops, miscounted strings!"); } diff --git a/usr.sbin/pkg_install/create/pl.c b/usr.sbin/pkg_install/create/pl.c index 3684def..a0a34e0 100644 --- a/usr.sbin/pkg_install/create/pl.c +++ b/usr.sbin/pkg_install/create/pl.c @@ -190,7 +190,7 @@ copy_plist(char *home, Package *plist) p->name); last_chdir = home; } - if (add_count > maxargs - where_count) { + if (add_count == -1 || add_count > maxargs - where_count) { cleanup(0); errx(2, __FUNCTION__ ": oops, miscounted strings!"); } @@ -228,7 +228,7 @@ copy_plist(char *home, Package *plist) " -C %s %s", mythere ? mythere : where, p->name); - if (add_count > maxargs - where_count) { + if (add_count == -1 || add_count > maxargs - where_count) { cleanup(0); errx(2, __FUNCTION__ ": oops, miscounted strings!"); } diff --git a/usr.sbin/pw/grupd.c b/usr.sbin/pw/grupd.c index edff76d..a2a0282 100644 --- a/usr.sbin/pw/grupd.c +++ b/usr.sbin/pw/grupd.c @@ -134,7 +134,7 @@ gr_update(struct group * grp, char const * group, int mode) char *grbuf = NULL; ENDGRENT(); - l = snprintf(pfx, sizeof pfx, "%s:", group); + snprintf(pfx, sizeof pfx, "%s:", group); /* * Update the group file diff --git a/usr.sbin/pw/pw_conf.c b/usr.sbin/pw/pw_conf.c index 0580091..e4c5a4a 100644 --- a/usr.sbin/pw/pw_conf.c +++ b/usr.sbin/pw/pw_conf.c @@ -420,6 +420,8 @@ write_userconfig(char const * file) for (j = k = 0; j < _UC_MAXSHELLS && system_shells[j] != NULL; j++) { char lbuf[64]; int l = snprintf(lbuf, sizeof lbuf, "%s\"%s\"", k ? "," : "", system_shells[j]); + if (l == -1) + l = 0; if (l + k + 1 < len || extendline(&buf, &len, len + LNBUFSZ) != -1) { strcpy(buf + k, lbuf); k += l; @@ -438,6 +440,8 @@ write_userconfig(char const * file) for (j = k = 0; j < config.numgroups && config.groups[j] != NULL; j++) { char lbuf[64]; int l = snprintf(lbuf, sizeof lbuf, "%s\"%s\"", k ? "," : "", config.groups[j]); + if (l == -1) + l = 0; if (l + k + 1 < len || extendline(&buf, &len, len + 1024) != -1) { strcpy(buf + k, lbuf); k += l; diff --git a/usr.sbin/pw/pwupd.c b/usr.sbin/pw/pwupd.c index fef3662..ec29b9e 100644 --- a/usr.sbin/pw/pwupd.c +++ b/usr.sbin/pw/pwupd.c @@ -166,6 +166,8 @@ pw_update(struct passwd * pwd, char const * user, int mode) else fmtpwentry(pwbuf, pwd, PWF_PASSWD); + if (l == -1) + l = 0; rc = fileupdate(getpwpath(_PASSWD), 0644, pwbuf, pfx, l, mode); if (rc == 0) { diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index 3ff3233..3866d73 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -901,7 +901,8 @@ fprintlog(f, flags, msg) v->iov_len = snprintf(greetings, sizeof greetings, "\r\n\7Message from syslogd@%s at %.24s ...\r\n", f->f_prevhost, ctime(&now)); - v++; + if (v->iov_len > 0) + v++; v->iov_base = ""; v->iov_len = 0; v++; @@ -995,7 +996,9 @@ fprintlog(f, flags, msg) else l = snprintf(line, sizeof line - 1, "<%d>%.15s %s", f->f_prevpri, iov[0].iov_base, iov[5].iov_base); - if (l > MAXLINE) + if (l < 0) + l = 0; + else if (l > MAXLINE) l = MAXLINE; if (finet) { |