diff options
author | Darren Tucker <dtucker@zip.com.au> | 2013-11-03 17:20:34 +1100 |
---|---|---|
committer | Darren Tucker <dtucker@zip.com.au> | 2013-11-03 17:20:34 +1100 |
commit | 710f3747352fb93a63e5b69b12379da37f5b3fa9 (patch) | |
tree | c3c72c89163211a54b74fd76cf4754bb13abc6c5 /openbsd-compat | |
parent | d52770452308e5c2e99f4da6edaaa77ef078b610 (diff) |
- (dtucker) [openbsd-compat/setproctitle.c] Handle error case form the 2nd
vsnprintf. From eric at openbsd via chl@.
Diffstat (limited to 'openbsd-compat')
-rw-r--r-- | openbsd-compat/setproctitle.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/openbsd-compat/setproctitle.c b/openbsd-compat/setproctitle.c index 2965f689e..a69db22a2 100644 --- a/openbsd-compat/setproctitle.c +++ b/openbsd-compat/setproctitle.c | |||
@@ -125,6 +125,7 @@ setproctitle(const char *fmt, ...) | |||
125 | va_list ap; | 125 | va_list ap; |
126 | char buf[1024], ptitle[1024]; | 126 | char buf[1024], ptitle[1024]; |
127 | size_t len; | 127 | size_t len; |
128 | int r; | ||
128 | extern char *__progname; | 129 | extern char *__progname; |
129 | #if SPT_TYPE == SPT_PSTAT | 130 | #if SPT_TYPE == SPT_PSTAT |
130 | union pstun pst; | 131 | union pstun pst; |
@@ -137,13 +138,16 @@ setproctitle(const char *fmt, ...) | |||
137 | 138 | ||
138 | strlcpy(buf, __progname, sizeof(buf)); | 139 | strlcpy(buf, __progname, sizeof(buf)); |
139 | 140 | ||
141 | r = -1; | ||
140 | va_start(ap, fmt); | 142 | va_start(ap, fmt); |
141 | if (fmt != NULL) { | 143 | if (fmt != NULL) { |
142 | len = strlcat(buf, ": ", sizeof(buf)); | 144 | len = strlcat(buf, ": ", sizeof(buf)); |
143 | if (len < sizeof(buf)) | 145 | if (len < sizeof(buf)) |
144 | vsnprintf(buf + len, sizeof(buf) - len , fmt, ap); | 146 | r = vsnprintf(buf + len, sizeof(buf) - len , fmt, ap); |
145 | } | 147 | } |
146 | va_end(ap); | 148 | va_end(ap); |
149 | if (r == -1 || (size_t)r >= sizeof(buf) - len) | ||
150 | return; | ||
147 | strnvis(ptitle, buf, sizeof(ptitle), | 151 | strnvis(ptitle, buf, sizeof(ptitle), |
148 | VIS_CSTYLE|VIS_NL|VIS_TAB|VIS_OCTAL); | 152 | VIS_CSTYLE|VIS_NL|VIS_TAB|VIS_OCTAL); |
149 | 153 | ||