Bläddra i källkod

HPCC-16271 Dafilesrv copyfile exception crash

Signed-off-by: Mark Kelly <mark.kelly@lexisnexis.com>
Mark Kelly 8 år sedan
förälder
incheckning
2516210654
2 ändrade filer med 25 tillägg och 18 borttagningar
  1. 21 11
      common/remote/sockfile.cpp
  2. 4 7
      dali/datest/datest.cpp

+ 21 - 11
common/remote/sockfile.cpp

@@ -365,7 +365,14 @@ const char *RFCStrings[] =
 };
 static const char *getRFCText(unsigned cmd)
 {
-    switch (cmd)
+    if (cmd > RFCmax)
+        cmd = RFCmax;
+    return RFCStrings[cmd];
+}
+
+static const char *getRFSERRText(unsigned err)
+{
+    switch (err)
     {
         case RFSERR_InvalidCommand:
             return "RFSERR_InvalidCommand";
@@ -442,11 +449,7 @@ static const char *getRFCText(unsigned cmd)
         case RFSERR_MaxQueueRequests:
             return "RFSERR_MaxQueueRequests";
     }
-
-    if (cmd > RFCmax)
-        return "RFSERR_UnknownCmd/Error";
-
-    return RFCStrings[cmd];
+    return "RFSERR_Unknown";
 }
 
 #define ThrottleText(throttleClass) #throttleClass
@@ -2966,20 +2969,27 @@ public:
 
 inline void appendErr(MemoryBuffer &reply, unsigned e)
 {
-    reply.append(e).append(getRFCText(e));
+    reply.append(e).append(getRFSERRText(e));
 }
 inline void appendErr2(MemoryBuffer &reply, unsigned e, unsigned v)
 {
     StringBuffer msg;
-    msg.append(getRFCText(e)).append(':').append(v);
+    msg.append(getRFSERRText(e)).append(':').append(v);
     reply.append(e).append(msg.str());
 }
 inline void appendErr3(MemoryBuffer &reply, unsigned e, int code, const char *errMsg)
 {
     StringBuffer msg;
+    msg.appendf("ERROR: %s(%d) '%s'", getRFSERRText(e), code, errMsg?errMsg:"");
+    reply.append(e);
+    reply.append(msg.str());
+}
+inline void appendCmdErr(MemoryBuffer &reply, unsigned e, int code, const char *errMsg)
+{
+    StringBuffer msg;
     msg.appendf("ERROR: %s(%d) '%s'", getRFCText(e), code, errMsg?errMsg:"");
-    // some errors are RemoteFileCommandType, some are RFSERR_*
     // RFCOpenIO needs remapping to non-zero for client to know its an error
+    // perhaps we should use code here instead of e ?
     if ((RemoteFileCommandType)e == RFCopenIO)
         e = RFSERR_OpenFailed;
     reply.append(e);
@@ -3324,7 +3334,7 @@ class CRemoteFileServer : implements IRemoteFileServer, public CInterface
             initSendBuffer(reply);
             StringBuffer s;
             e->errorMessage(s);
-            appendErr3(reply, cmd, e->errorCode(), s.str());
+            appendCmdErr(reply, cmd, e->errorCode(), s.str());
             parent->appendError(cmd, this, cmd, reply);
             sendBuffer(socket, reply);
             return false;
@@ -4989,7 +4999,7 @@ public:
             ret = false;
             StringBuffer s;
             e->errorMessage(s);
-            appendErr3(reply, cmd, e->errorCode(), s.str());
+            appendCmdErr(reply, cmd, e->errorCode(), s.str());
             e->Release();
         }
         if (!ret) // append error string

+ 4 - 7
dali/datest/datest.cpp

@@ -710,19 +710,16 @@ struct RecordStruct
 // #define NRECS ((__int64)1024*1024*500/sizeof(RecordStruct)) // i.e. ~500MB
 // #define NRECS ((__int64)1024*500/sizeof(RecordStruct)) // i.e. ~500KB
 
-void TestCopyFile(char *srcfname, char *dstfname)
+void TestCopyFile(char *srcfname, char *dstfname) // TEST_COPYFILE
 {
     // example cmdline: datest srcfile //1.2.3.4:7100/home/username/dstfile
-    IFile *srcfile = createIFile(srcfname);
-    IFileIO *srcio = srcfile->open(IFOcreate);
+    Owned<IFile> srcfile = createIFile(srcfname);
+    Owned<IFileIO> srcio = srcfile->open(IFOcreate);
     char buf[100] = { "TestCopyFile" };
     srcio->write(0, 18, buf);
     srcio->close();
-    srcio->Release();
-    IFile *dstfile = createIFile(dstfname);
+    Owned<IFile> dstfile = createIFile(dstfname);
     srcfile->copyTo(dstfile,0x100000,NULL,false);
-    srcfile->Release();
-    dstfile->Release();
 }
 
 void TestRemoteFile3(int nfiles, int fsizemb)