#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
+#include <assert.h>
#include <stdarg.h>
#define PUTTY_DO_GLOBALS /* actually _define_ globals */
va_end(ap);
fputc('\n', stderr);
WSACleanup();
- exit(1);
+ cleanup_exit(1);
}
void connection_fatal(char *p, ...)
{
va_end(ap);
fputc('\n', stderr);
WSACleanup();
- exit(1);
+ cleanup_exit(1);
}
static char *password = NULL;
HANDLE h = (is_stderr ? errhandle : outhandle);
int osize, esize;
+ assert(len > 0);
+
if (is_stderr) {
bufchain_add(&stderr_data, data, len);
try_output(1);
}
}
} else {
- int len = sizeof(cfg.remote_cmd) - 1;
- char *cp = cfg.remote_cmd;
- int len2;
-
- strncpy(cp, p, len);
- cp[len] = '\0';
- len2 = strlen(cp);
- len -= len2;
- cp += len2;
- while (--argc) {
- if (len > 0)
- len--, *cp++ = ' ';
- strncpy(cp, *++argv, len);
- cp[len] = '\0';
- len2 = strlen(cp);
- len -= len2;
- cp += len2;
+ char *command;
+ int cmdlen, cmdsize;
+ cmdlen = cmdsize = 0;
+ command = NULL;
+
+ while (argc) {
+ while (*p) {
+ if (cmdlen >= cmdsize) {
+ cmdsize = cmdlen + 512;
+ command = srealloc(command, cmdsize);
+ }
+ command[cmdlen++]=*p++;
+ }
+ if (cmdlen >= cmdsize) {
+ cmdsize = cmdlen + 512;
+ command = srealloc(command, cmdsize);
+ }
+ command[cmdlen++]=' '; /* always add trailing space */
+ if (--argc) p = *++argv;
}
+ if (cmdlen) command[--cmdlen]='\0';
+ /* change trailing blank to NUL */
+ cfg.remote_cmd_ptr = command;
+ cfg.remote_cmd_ptr2 = NULL;
cfg.nopty = TRUE; /* command => no terminal */
+
break; /* done with cmdline */
}
}
if (!CreateThread(NULL, 0, stdout_write_thread,
&odata, 0, &out_threadid)) {
fprintf(stderr, "Unable to create output thread\n");
- exit(1);
+ cleanup_exit(1);
}
edata.event = stderrevent;
edata.eventback = CreateEvent(NULL, FALSE, FALSE, NULL);
if (!CreateThread(NULL, 0, stdout_write_thread,
&edata, 0, &err_threadid)) {
fprintf(stderr, "Unable to create error output thread\n");
- exit(1);
+ cleanup_exit(1);
}
while (1) {
if (!CreateThread(NULL, 0, stdin_read_thread,
&idata, 0, &in_threadid)) {
fprintf(stderr, "Unable to create input thread\n");
- exit(1);
+ cleanup_exit(1);
}
sending = TRUE;
}
odata.busy = 0;
if (!odata.writeret) {
fprintf(stderr, "Unable to write to standard output\n");
- exit(0);
+ cleanup_exit(0);
}
bufchain_consume(&stdout_data, odata.lenwritten);
if (bufchain_size(&stdout_data) > 0)
edata.busy = 0;
if (!edata.writeret) {
fprintf(stderr, "Unable to write to standard output\n");
- exit(0);
+ cleanup_exit(0);
}
bufchain_consume(&stderr_data, edata.lenwritten);
if (bufchain_size(&stderr_data) > 0)