hush: trivial buglet found by randomconfig testing
[oweals/busybox.git] / miscutils / crontab.c
index d442272f0cb4258ed51a7c59617a49c2aea21c8e..76c382e8fa35eb90aac528c3ed896c8aafd41cb0 100644 (file)
@@ -10,7 +10,7 @@
  * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
  */
 
-#include "busybox.h"
+#include "libbb.h"
 
 #ifndef CRONTABS
 #define CRONTABS        "/var/spool/cron/crontabs"
@@ -31,6 +31,7 @@ static void EditFile(const char *user, const char *file);
 static int GetReplaceStream(const char *user, const char *file);
 static int ChangeUser(const char *user, short dochdir);
 
+int crontab_main(int ac, char **av);
 int crontab_main(int ac, char **av)
 {
        enum { NONE, EDIT, LIST, REPLACE, DELETE } option = NONE;
@@ -290,8 +291,7 @@ static void EditFile(const char *user, const char *file)
                /*
                 * CHILD - change user and run editor
                 */
-               char *ptr;
-               char visual[1024];
+               const char *ptr;
 
                if (ChangeUser(user, 1) < 0)
                        exit(0);
@@ -299,10 +299,9 @@ static void EditFile(const char *user, const char *file)
                if (ptr == NULL || strlen(ptr) > 256)
                        ptr = PATH_VI;
 
-               snprintf(visual, sizeof(visual), "%s %s", ptr, file);
-               execl(DEFAULT_SHELL, DEFAULT_SHELL, "-c", visual, NULL);
-               perror("exec");
-               exit(0);
+               ptr = xasprintf("%s %s", ptr, file);
+               execl(DEFAULT_SHELL, DEFAULT_SHELL, "-c", ptr, NULL);
+               bb_perror_msg_and_die("exec");
        }
        if (pid < 0) {
                /*