aboutsummaryrefslogtreecommitdiffstats
path: root/nt/cmdproxy.c
diff options
context:
space:
mode:
Diffstat (limited to 'nt/cmdproxy.c')
-rw-r--r--nt/cmdproxy.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/nt/cmdproxy.c b/nt/cmdproxy.c
index aae852bf4fa..4f2d113a900 100644
--- a/nt/cmdproxy.c
+++ b/nt/cmdproxy.c
@@ -35,6 +35,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
35#include <stdlib.h> /* getenv */ 35#include <stdlib.h> /* getenv */
36#include <string.h> /* strlen */ 36#include <string.h> /* strlen */
37 37
38/* We don't want to include stdio.h because we are already duplicating
39 lots of it here */
40extern int _snprintf (char *buffer, size_t count, const char *format, ...);
38 41
39/******* Mock C library routines *********************************/ 42/******* Mock C library routines *********************************/
40 43
@@ -604,6 +607,7 @@ main (int argc, char ** argv)
604 { 607 {
605 char * p; 608 char * p;
606 int extra_arg_space = 0; 609 int extra_arg_space = 0;
610 int maxlen, remlen;
607 int run_command_dot_com; 611 int run_command_dot_com;
608 612
609 progname = getenv ("COMSPEC"); 613 progname = getenv ("COMSPEC");
@@ -635,21 +639,27 @@ main (int argc, char ** argv)
635 case path contains spaces (fortunately it can't contain 639 case path contains spaces (fortunately it can't contain
636 quotes, since they are illegal in path names). */ 640 quotes, since they are illegal in path names). */
637 641
638 buf = p = alloca (strlen (progname) + extra_arg_space + 642 remlen = maxlen =
639 strlen (cmdline) + 16); 643 strlen (progname) + extra_arg_space + strlen (cmdline) + 16;
644 buf = p = alloca (maxlen + 1);
640 645
641 /* Quote progname in case it contains spaces. */ 646 /* Quote progname in case it contains spaces. */
642 p += wsprintf (p, "\"%s\"", progname); 647 p += _snprintf (p, remlen, "\"%s\"", progname);
648 remlen = maxlen - (p - buf);
643 649
644 /* Include pass_through_args verbatim; these are just switches 650 /* Include pass_through_args verbatim; these are just switches
645 so should not need quoting. */ 651 so should not need quoting. */
646 for (argv = pass_through_args; *argv != NULL; ++argv) 652 for (argv = pass_through_args; *argv != NULL; ++argv)
647 p += wsprintf (p, " %s", *argv); 653 {
654 p += _snprintf (p, remlen, " %s", *argv);
655 remlen = maxlen - (p - buf);
656 }
648 657
649 if (run_command_dot_com) 658 if (run_command_dot_com)
650 wsprintf(p, " /e:%d /c %s", envsize, cmdline); 659 _snprintf (p, remlen, " /e:%d /c %s", envsize, cmdline);
651 else 660 else
652 wsprintf(p, " /c %s", cmdline); 661 _snprintf (p, remlen, " /c %s", cmdline);
662 remlen = maxlen - (p - buf);
653 cmdline = buf; 663 cmdline = buf;
654 } 664 }
655 else 665 else
@@ -669,19 +679,27 @@ main (int argc, char ** argv)
669 else 679 else
670 path[0] = '\0'; 680 path[0] = '\0';
671 681
672 cmdline = p = alloca (strlen (progname) + extra_arg_space + 682 remlen = maxlen =
673 strlen (path) + 13); 683 strlen (progname) + extra_arg_space + strlen (path) + 13;
684 cmdline = p = alloca (maxlen + 1);
674 685
675 /* Quote progname in case it contains spaces. */ 686 /* Quote progname in case it contains spaces. */
676 p += wsprintf (p, "\"%s\" %s", progname, path); 687 p += _snprintf (p, remlen, "\"%s\" %s", progname, path);
688 remlen = maxlen - (p - cmdline);
677 689
678 /* Include pass_through_args verbatim; these are just switches 690 /* Include pass_through_args verbatim; these are just switches
679 so should not need quoting. */ 691 so should not need quoting. */
680 for (argv = pass_through_args; *argv != NULL; ++argv) 692 for (argv = pass_through_args; *argv != NULL; ++argv)
681 p += wsprintf (p, " %s", *argv); 693 {
694 p += _snprintf (p, remlen, " %s", *argv);
695 remlen = maxlen - (p - cmdline);
696 }
682 697
683 if (run_command_dot_com) 698 if (run_command_dot_com)
684 wsprintf (p, " /e:%d", envsize); 699 {
700 _snprintf (p, remlen, " /e:%d", envsize);
701 remlen = maxlen - (p - cmdline);
702 }
685 } 703 }
686 } 704 }
687 705