From a04746f766005d9183edc903c5da4ec9e21abf3b Mon Sep 17 00:00:00 2001 From: zolliker Date: Mon, 20 Oct 2008 15:15:14 +0000 Subject: [PATCH] - treat arguments of remserver command correctly (including empty strings) --- remob.c | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/remob.c b/remob.c index beaec2dc..9a407a7c 100644 --- a/remob.c +++ b/remob.c @@ -196,7 +196,6 @@ static int RemSetInterest(RemChannel *rc) { static void RemConnect(RemServer *remserver, int both) { /* open channel 0 or both channels, if not yet opened */ int iRet; - char buf[256]; mkChannel *chan; int i; RemChannel *rc; @@ -279,9 +278,9 @@ static int RemTransact(RemServer *remserver, int nChan, SConnection *pCon, "!blabla" skip lines starting with blabla ">" write untreated lines to pCon */ - char buf[256]; + char *buffer; + int bufferLen; int iRet; - int i, typ; char *arg, *val, *endp; float *f; va_list ap; @@ -296,9 +295,16 @@ static int RemTransact(RemServer *remserver, int nChan, SConnection *pCon, } } tryagain: - snprintf(buf, sizeof buf, "transact %s\n", cmd); + bufferLen = strlen(cmd)+16; + buffer=malloc(bufferLen); + if (buffer == NULL) { + SCPrintf(pCon, eError, "ERROR: can not get another %d bytes", bufferLen); + return 0; + } + snprintf(buffer, bufferLen, "transact %s\n", cmd); RemConnect(remserver, nChan); - iRet = RemWrite(rc, buf); + iRet = RemWrite(rc, buffer); + free(buffer); if (iRet < 0) goto close; iRet = RemRead(rc, 2000); @@ -342,20 +348,17 @@ tryagain: close: if (iRet == 0) { if (try == 1) { - snprintf(buf, sizeof(buf), "ERROR: timeout on %s", remserver->name); - SCWrite(pCon,buf,eError); + SCPrintf(pCon, eError, "ERROR: timeout on %s", remserver->name); rc->timeout = 1; return iRet; } else { - snprintf(buf, sizeof(buf), "WARNING: timeout on %s", remserver->name); - SCWrite(pCon,buf,eError); + SCPrintf(pCon, eError, "WARNING: timeout on %s", remserver->name); } } RemDisconnect(remserver); try--; if (try>0) goto tryagain; - snprintf(buf, sizeof(buf), "ERROR: no connection to %s", remserver->name); - SCWrite(pCon,buf,eError); + SCPrintf(pCon, eError, "ERROR: no connection to %s", remserver->name); return iRet; } /*-------------------------------------------------------------------------*/ @@ -637,7 +640,6 @@ static void RemobKill(void *self) { int RemServerAction(SConnection *pCon, SicsInterp *pSics, void *pData, int argc, char *argv[]) { RemServer *remserver = pData; - char buf[512]; TokenList *pList = NULL; TokenList *pCurrent; TokenList *pName; @@ -652,6 +654,7 @@ int RemServerAction(SConnection *pCon, SicsInterp *pSics, void *pData, Remob *p, *next; int rights, nChan; RemChannel *rc; + char *args; assert(pCon); assert(pSics); @@ -681,13 +684,10 @@ int RemServerAction(SConnection *pCon, SicsInterp *pSics, void *pData, argv[0], remserver->host, remserver->port, thishostname, serverport); } else if (argc>2 && strcasecmp(argv[1],"nowait") == 0) { RemConnect(remserver, nChan); - for (i=2; i2) { - RemWrite(rc, " "); - } - RemWrite(rc, argv[i]); - } + args = Arg2Tcl(argc-2, argv+2, NULL, 0); + RemWrite(rc, args); RemWrite(rc, "\n"); + free(args); } else if (argc==2 && strcasecmp(argv[1],"markForDel") == 0) { p = remserver->objList; while (p) { @@ -708,11 +708,9 @@ int RemServerAction(SConnection *pCon, SicsInterp *pSics, void *pData, p = next; } } else { - pos=0; - for (i=1; i", NULL); + args = Arg2Tcl(argc-1, argv+1, NULL, 0); + iRet = RemTransact(remserver, nChan, pCon, args, ">", NULL); + free(args); return iRet; } return 1;