summaryrefslogtreecommitdiff
path: root/openbsd-compat/setproctitle.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2008-05-16 10:01:54 +1000
committerDamien Miller <djm@mindrot.org>2008-05-16 10:01:54 +1000
commitc5750226af60d321f11eea8c316c958048ee000d (patch)
tree97bd83dfa22f2bd6aa97ab3668c150ebaf5838df /openbsd-compat/setproctitle.c
parent55754fb0024cb84f99a72e15196fa03456a0c097 (diff)
- (djm) Force string arguments to replacement setproctitle() though
strnvis first. Ok dtucker@
Diffstat (limited to 'openbsd-compat/setproctitle.c')
-rw-r--r--openbsd-compat/setproctitle.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/openbsd-compat/setproctitle.c b/openbsd-compat/setproctitle.c
index b511f6649..2965f689e 100644
--- a/openbsd-compat/setproctitle.c
+++ b/openbsd-compat/setproctitle.c
@@ -43,6 +43,8 @@
43#endif 43#endif
44#include <string.h> 44#include <string.h>
45 45
46#include <vis.h>
47
46#define SPT_NONE 0 /* don't use it at all */ 48#define SPT_NONE 0 /* don't use it at all */
47#define SPT_PSTAT 1 /* use pstat(PSTAT_SETCMD, ...) */ 49#define SPT_PSTAT 1 /* use pstat(PSTAT_SETCMD, ...) */
48#define SPT_REUSEARGV 2 /* cover argv with title information */ 50#define SPT_REUSEARGV 2 /* cover argv with title information */
@@ -121,7 +123,7 @@ setproctitle(const char *fmt, ...)
121{ 123{
122#if SPT_TYPE != SPT_NONE 124#if SPT_TYPE != SPT_NONE
123 va_list ap; 125 va_list ap;
124 char buf[1024]; 126 char buf[1024], ptitle[1024];
125 size_t len; 127 size_t len;
126 extern char *__progname; 128 extern char *__progname;
127#if SPT_TYPE == SPT_PSTAT 129#if SPT_TYPE == SPT_PSTAT
@@ -142,14 +144,16 @@ setproctitle(const char *fmt, ...)
142 vsnprintf(buf + len, sizeof(buf) - len , fmt, ap); 144 vsnprintf(buf + len, sizeof(buf) - len , fmt, ap);
143 } 145 }
144 va_end(ap); 146 va_end(ap);
147 strnvis(ptitle, buf, sizeof(ptitle),
148 VIS_CSTYLE|VIS_NL|VIS_TAB|VIS_OCTAL);
145 149
146#if SPT_TYPE == SPT_PSTAT 150#if SPT_TYPE == SPT_PSTAT
147 pst.pst_command = buf; 151 pst.pst_command = ptitle;
148 pstat(PSTAT_SETCMD, pst, strlen(buf), 0, 0); 152 pstat(PSTAT_SETCMD, pst, strlen(ptitle), 0, 0);
149#elif SPT_TYPE == SPT_REUSEARGV 153#elif SPT_TYPE == SPT_REUSEARGV
150/* debug("setproctitle: copy \"%s\" into len %d", 154/* debug("setproctitle: copy \"%s\" into len %d",
151 buf, argv_env_len); */ 155 buf, argv_env_len); */
152 len = strlcpy(argv_start, buf, argv_env_len); 156 len = strlcpy(argv_start, ptitle, argv_env_len);
153 for(; len < argv_env_len; len++) 157 for(; len < argv_env_len; len++)
154 argv_start[len] = SPT_PADCHAR; 158 argv_start[len] = SPT_PADCHAR;
155#endif 159#endif