diff options
-rw-r--r-- | usr.sbin/cron/crontab.c | 22 | ||||
-rw-r--r-- | usr.sbin/cron/database.c | 8 | ||||
-rw-r--r-- | usr.sbin/cron/entry.c | 24 | ||||
-rw-r--r-- | usr.sbin/cron/env.c | 6 | ||||
-rw-r--r-- | usr.sbin/cron/misc.c | 47 |
5 files changed, 36 insertions, 71 deletions
diff --git a/usr.sbin/cron/crontab.c b/usr.sbin/cron/crontab.c index 02a9c99dabc..ba2b7688cdb 100644 --- a/usr.sbin/cron/crontab.c +++ b/usr.sbin/cron/crontab.c @@ -1,4 +1,4 @@ -/* $OpenBSD: crontab.c,v 1.44 2004/06/17 22:11:55 millert Exp $ */ +/* $OpenBSD: crontab.c,v 1.45 2004/06/22 03:15:33 avsm Exp $ */ /* Copyright 1988,1990,1993,1994 by Paul Vixie * All rights reserved @@ -22,7 +22,7 @@ */ #if !defined(lint) && !defined(LINT) -static char const rcsid[] = "$OpenBSD: crontab.c,v 1.44 2004/06/17 22:11:55 millert Exp $"; +static char const rcsid[] = "$OpenBSD: crontab.c,v 1.45 2004/06/22 03:15:33 avsm Exp $"; #endif /* crontab - install and manage per-user crontab files @@ -234,7 +234,7 @@ list_cmd(void) { int ch; log_it(RealUser, Pid, "LIST", User); - if (!glue_strings(n, sizeof n, SPOOL_DIR, User, '/')) { + if (snprintf(n, sizeof n, "%s/%s", SPOOL_DIR, User) >= sizeof(n)) { fprintf(stderr, "path too long\n"); exit(ERROR_EXIT); } @@ -259,7 +259,7 @@ delete_cmd(void) { char n[MAX_FNAME]; log_it(RealUser, Pid, "DELETE", User); - if (!glue_strings(n, sizeof n, SPOOL_DIR, User, '/')) { + if (snprintf(n, sizeof n, "%s/%s", SPOOL_DIR, User) >= sizeof(n)) { fprintf(stderr, "path too long\n"); exit(ERROR_EXIT); } @@ -291,7 +291,7 @@ edit_cmd(void) { PID_T pid, xpid; log_it(RealUser, Pid, "BEGIN EDIT", User); - if (!glue_strings(n, sizeof n, SPOOL_DIR, User, '/')) { + if (snprintf(n, sizeof n, "%s/%s", SPOOL_DIR, User) >= sizeof(n)) { fprintf(stderr, "path too long\n"); exit(ERROR_EXIT); } @@ -321,8 +321,8 @@ edit_cmd(void) { (void)signal(SIGINT, SIG_IGN); (void)signal(SIGQUIT, SIG_IGN); - if (!glue_strings(Filename, sizeof Filename, _PATH_TMP, - "crontab.XXXXXXXXXX", '/')) { + if (snprintf(Filename, sizeof Filename, "%s/crontab.XXXXXXXXXX", + _PATH_TMP) >= sizeof(Filename)) { fprintf(stderr, "path too long\n"); goto fatal; } @@ -400,7 +400,7 @@ edit_cmd(void) { perror(_PATH_TMP); exit(ERROR_EXIT); } - if (!glue_strings(q, sizeof q, editor, Filename, ' ')) { + if (snprintf(q, sizeof q, "%s %s", editor, Filename) >= sizeof(q)) { fprintf(stderr, "%s: editor command line too long\n", ProgramName); exit(ERROR_EXIT); @@ -508,8 +508,8 @@ replace_cmd(void) { fprintf(stderr, "%s: Cannot allocate memory.\n", ProgramName); return (-2); } - if (!glue_strings(TempFilename, sizeof TempFilename, SPOOL_DIR, - "tmp.XXXXXXXXXX", '/')) { + if (snprintf(TempFilename, sizeof TempFilename, "%s/tmp.XXXXXXXXX", SPOOL_DIR) >= + sizeof(TempFilename)) { TempFilename[0] = '\0'; fprintf(stderr, "path too long\n"); return (-2); @@ -611,7 +611,7 @@ replace_cmd(void) { goto done; } - if (!glue_strings(n, sizeof n, SPOOL_DIR, User, '/')) { + if (snprintf(n, sizeof n, "%s/%s", SPOOL_DIR, User) >= sizeof(n)) { fprintf(stderr, "path too long\n"); error = -2; goto done; diff --git a/usr.sbin/cron/database.c b/usr.sbin/cron/database.c index e2fe8f97bf3..c14132dfcf3 100644 --- a/usr.sbin/cron/database.c +++ b/usr.sbin/cron/database.c @@ -1,4 +1,4 @@ -/* $OpenBSD: database.c,v 1.15 2004/06/17 22:11:55 millert Exp $ */ +/* $OpenBSD: database.c,v 1.16 2004/06/22 03:15:33 avsm Exp $ */ /* Copyright 1988,1990,1993,1994 by Paul Vixie * All rights reserved @@ -22,7 +22,7 @@ */ #if !defined(lint) && !defined(LINT) -static char const rcsid[] = "$OpenBSD: database.c,v 1.15 2004/06/17 22:11:55 millert Exp $"; +static char const rcsid[] = "$OpenBSD: database.c,v 1.16 2004/06/22 03:15:33 avsm Exp $"; #endif /* vix 26jan87 [RCS has the log] @@ -109,8 +109,8 @@ load_database(cron_db *old_db) { if (strlcpy(fname, dp->d_name, sizeof fname) >= sizeof fname) continue; /* XXX log? */ - if (!glue_strings(tabname, sizeof tabname, SPOOL_DIR, - fname, '/')) + if (snprintf(tabname, sizeof tabname, "%s/%s", SPOOL_DIR, fname) >= + sizeof(tabname)) continue; /* XXX log? */ process_crontab(fname, fname, tabname, diff --git a/usr.sbin/cron/entry.c b/usr.sbin/cron/entry.c index 64aff1b12fb..25066967f7b 100644 --- a/usr.sbin/cron/entry.c +++ b/usr.sbin/cron/entry.c @@ -1,4 +1,4 @@ -/* $OpenBSD: entry.c,v 1.27 2004/06/17 22:11:55 millert Exp $ */ +/* $OpenBSD: entry.c,v 1.28 2004/06/22 03:15:33 avsm Exp $ */ /* * Copyright 1988,1990,1993,1994 by Paul Vixie @@ -23,7 +23,7 @@ */ #if !defined(lint) && !defined(LINT) -static char const rcsid[] = "$OpenBSD: entry.c,v 1.27 2004/06/17 22:11:55 millert Exp $"; +static char const rcsid[] = "$OpenBSD: entry.c,v 1.28 2004/06/22 03:15:33 avsm Exp $"; #endif /* vix 26jan87 [RCS'd; rest of log is in RCS file] @@ -279,8 +279,8 @@ load_entry(FILE *file, void (*error_func)(const char *), struct passwd *pw, char goto eof; } if (!env_get("SHELL", e->envp)) { - if (glue_strings(envstr, sizeof envstr, "SHELL", - _PATH_BSHELL, '=')) { + if (snprintf(envstr, sizeof envstr, "SHELL=%s", _PATH_BSHELL) >= + sizeof(envstr)) { if ((tenvp = env_set(e->envp, envstr)) == NULL) { ecode = e_memory; goto eof; @@ -290,8 +290,8 @@ load_entry(FILE *file, void (*error_func)(const char *), struct passwd *pw, char log_it("CRON", getpid(), "error", "can't set SHELL"); } if (!env_get("HOME", e->envp)) { - if (glue_strings(envstr, sizeof envstr, "HOME", - pw->pw_dir, '=')) { + if (snprintf(envstr, sizeof envstr, "HOME=%s", pw->pw_dir) >= + sizeof(envstr)) { if ((tenvp = env_set(e->envp, envstr)) == NULL) { ecode = e_memory; goto eof; @@ -303,8 +303,8 @@ load_entry(FILE *file, void (*error_func)(const char *), struct passwd *pw, char #ifndef LOGIN_CAP /* If login.conf is in use we will get the default PATH later. */ if (!env_get("PATH", e->envp)) { - if (glue_strings(envstr, sizeof envstr, "PATH", - _PATH_DEFPATH, '=')) { + if (snprintf(envstr, sizeof envstr, "PATH=%s", _PATH_DEFPATH) >= + sizeof(envstr)) { if ((tenvp = env_set(e->envp, envstr)) == NULL) { ecode = e_memory; goto eof; @@ -314,8 +314,8 @@ load_entry(FILE *file, void (*error_func)(const char *), struct passwd *pw, char log_it("CRON", getpid(), "error", "can't set PATH"); } #endif /* LOGIN_CAP */ - if (glue_strings(envstr, sizeof envstr, "LOGNAME", - pw->pw_name, '=')) { + if (snprintf(envstr, sizeof envstr, "LOGNAME=%s", pw->pw_name) >= + sizeof(envstr)) { if ((tenvp = env_set(e->envp, envstr)) == NULL) { ecode = e_memory; goto eof; @@ -324,8 +324,8 @@ load_entry(FILE *file, void (*error_func)(const char *), struct passwd *pw, char } else log_it("CRON", getpid(), "error", "can't set LOGNAME"); #if defined(BSD) || defined(__linux) - if (glue_strings(envstr, sizeof envstr, "USER", - pw->pw_name, '=')) { + if (snprintf(envstr, sizeof envstr, "USER=%s", pw->pw_name) >= + sizeof(envstr)) { if ((tenvp = env_set(e->envp, envstr)) == NULL) { ecode = e_memory; goto eof; diff --git a/usr.sbin/cron/env.c b/usr.sbin/cron/env.c index e8769a680cb..a0e4c1b096e 100644 --- a/usr.sbin/cron/env.c +++ b/usr.sbin/cron/env.c @@ -1,4 +1,4 @@ -/* $OpenBSD: env.c,v 1.16 2004/06/17 22:11:55 millert Exp $ */ +/* $OpenBSD: env.c,v 1.17 2004/06/22 03:15:33 avsm Exp $ */ /* Copyright 1988,1990,1993,1994 by Paul Vixie * All rights reserved @@ -22,7 +22,7 @@ */ #if !defined(lint) && !defined(LINT) -static char const rcsid[] = "$OpenBSD: env.c,v 1.16 2004/06/17 22:11:55 millert Exp $"; +static char const rcsid[] = "$OpenBSD: env.c,v 1.17 2004/06/22 03:15:33 avsm Exp $"; #endif #include "cron.h" @@ -227,7 +227,7 @@ load_env(char *envstr, FILE *f) { * This can't overflow because get_string() limited the size of the * name and val fields. Still, it doesn't hurt to be careful... */ - if (!glue_strings(envstr, MAX_ENVSTR, name, val, '=')) + if (snprintf(envstr, MAX_ENVSTR, "%s=%s", name, val) >= MAX_ENVSTR) return (FALSE); Debug(DPARS, ("load_env, <%s> <%s> -> <%s>\n", name, val, envstr)) return (TRUE); diff --git a/usr.sbin/cron/misc.c b/usr.sbin/cron/misc.c index 017e8e0a7ce..565b51d9939 100644 --- a/usr.sbin/cron/misc.c +++ b/usr.sbin/cron/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.30 2004/06/17 22:11:55 millert Exp $ */ +/* $OpenBSD: misc.c,v 1.31 2004/06/22 03:15:33 avsm Exp $ */ /* Copyright 1988,1990,1993,1994 by Paul Vixie * All rights reserved @@ -22,7 +22,7 @@ */ #if !defined(lint) && !defined(LINT) -static char const rcsid[] = "$OpenBSD: misc.c,v 1.30 2004/06/17 22:11:55 millert Exp $"; +static char const rcsid[] = "$OpenBSD: misc.c,v 1.31 2004/06/22 03:15:33 avsm Exp $"; #endif /* vix 26jan87 [RCS has the rest of the log] @@ -50,41 +50,6 @@ static int LogFD = ERR; static int syslog_open = FALSE; #endif -/* - * glue_strings is the overflow-safe equivalent of - * snprintf(buffer, buffer_size, "%s%c%s", a, separator, b); - * - * returns 1 on success, 0 on failure. 'buffer' MUST NOT be used if - * glue_strings fails. - */ -int -glue_strings(char *buffer, size_t buffer_size, const char *a, const char *b, - char separator) -{ - char *buf; - char *buf_end; - - if (buffer_size <= 0) - return (0); - buf_end = buffer + buffer_size; - buf = buffer; - - for ( /* nothing */; buf < buf_end && *a != '\0'; buf++, a++ ) - *buf = *a; - if (buf == buf_end) - return (0); - if (separator != '/' || buf == buffer || buf[-1] != '/') - *buf++ = separator; - if (buf == buf_end) - return (0); - for ( /* nothing */; buf < buf_end && *b != '\0'; buf++, b++ ) - *buf = *b; - if (buf == buf_end) - return (0); - *buf = '\0'; - return (1); -} - int strcmp_until(const char *left, const char *right, char until) { while (*left && *left != until && *left == *right) { @@ -769,8 +734,8 @@ open_socket() "can't make socket non-blocking"); exit(ERROR_EXIT); } - if (!glue_strings(s_un.sun_path, sizeof s_un.sun_path, SPOOL_DIR, - CRONSOCK, '/')) { + if (snprintf(s_un.sun_path, sizeof s_un.sun_path, "%s/%s", + SPOOL_DIR, CRONSOCK) >= sizeof(s_un.sun_path)) { fprintf(stderr, "%s/%s: path too long\n", SPOOL_DIR, CRONSOCK); log_it("CRON", getpid(), "DEATH", "path too long"); exit(ERROR_EXIT); @@ -811,8 +776,8 @@ poke_daemon(const char *spool_dir, unsigned char cookie) { return; } - if (glue_strings(s_un.sun_path, sizeof s_un.sun_path, SPOOL_DIR, - CRONSOCK, '/')) { + if (snprintf(s_un.sun_path, sizeof s_un.sun_path, "%s/%s", + SPOOL_DIR, CRONSOCK) >= sizeof(s_un.sun_path)) { s_un.sun_family = AF_UNIX; #ifdef SUN_LEN s_un.sun_len = SUN_LEN(&s_un); |