X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=pppd%2Futils.c;h=23189d0ad105bd49f9c00c274ab6340cfd6ffb09;hb=21c69e670a9f3f0b4cb201849146fd92f78cdeb9;hp=3ac1b60926d20014808dcaf708d59f6adb33ee1a;hpb=6edf252483b30dbcdcc5059f01831455365d5b6e;p=ppp.git diff --git a/pppd/utils.c b/pppd/utils.c index 3ac1b60..23189d0 100644 --- a/pppd/utils.c +++ b/pppd/utils.c @@ -59,7 +59,6 @@ #include "fsm.h" #include "lcp.h" -static const char rcsid[] = RCSID; #if defined(SUNOS4) extern char *strerror(); @@ -167,6 +166,7 @@ vslprintf(buf, buflen, fmt, args) u_int32_t ip; static char hexchars[] = "0123456789abcdef"; struct buffer_info bufinfo; + int termch; buf0 = buf; --buflen; @@ -300,13 +300,17 @@ vslprintf(buf, buflen, fmt, args) p = (unsigned char *)""; if (fillch == '0' && prec >= 0) { n = prec; + termch = -1; /* matches no unsigned char value */ } else { - n = strlen((char *)p); - if (prec >= 0 && n > prec) + n = buflen; + if (prec != -1 && n > prec) n = prec; + termch = 0; /* stop on null byte */ } while (n > 0 && buflen > 0) { c = *p++; + if (c == termch) + break; --n; if (!quoted && c >= 0x80) { OUTCHAR('M'); @@ -386,9 +390,9 @@ vslprintf(buf, buflen, fmt, args) } len = num + sizeof(num) - 1 - str; } else { - len = strlen(str); - if (prec >= 0 && len > prec) - len = prec; + for (len = 0; len < buflen && (prec == -1 || len < prec); ++len) + if (str[len] == 0) + break; } if (width > 0) { if (width > buflen) @@ -831,7 +835,7 @@ complete_read(int fd, void *buf, size_t count) for (done = 0; done < count; ) { nb = read(fd, ptr, count - done); if (nb < 0) { - if (errno == EINTR) + if (errno == EINTR && !got_sigterm) continue; return -1; }