You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by fp...@apache.org on 2016/08/10 20:55:44 UTC

svn commit: r1755855 - in /zookeeper/branches/branch-3.5: CHANGES.txt src/c/README src/c/src/cli.c

Author: fpj
Date: Wed Aug 10 20:55:43 2016
New Revision: 1755855

URL: http://svn.apache.org/viewvc?rev=1755855&view=rev
Log:
Fix command handling in the C client shell (phunt via fpj)

Modified:
    zookeeper/branches/branch-3.5/CHANGES.txt
    zookeeper/branches/branch-3.5/src/c/README
    zookeeper/branches/branch-3.5/src/c/src/cli.c

Modified: zookeeper/branches/branch-3.5/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/CHANGES.txt?rev=1755855&r1=1755854&r2=1755855&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/CHANGES.txt (original)
+++ zookeeper/branches/branch-3.5/CHANGES.txt Wed Aug 10 20:55:43 2016
@@ -20,6 +20,8 @@ BUGFIXES:
   ZOOKEEPER-2074: Incorrect exit codes for "./zkCli.sh cmd arg"
   (Abraham Fine via phunt)
 
+  Fix command handling in the C client shell (phunt via fpj)
+  
 IMPROVEMENTS:
 
 

Modified: zookeeper/branches/branch-3.5/src/c/README
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/c/README?rev=1755855&r1=1755854&r2=1755855&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/c/README (original)
+++ zookeeper/branches/branch-3.5/src/c/README Wed Aug 10 20:55:43 2016
@@ -72,7 +72,12 @@ tar downloaded from Apache please skip t
    other document formats please use "./configure --help"
 
 
-USING THE CLIENT
+EXAMPLE/SAMPLE C CLIENT SHELL
+
+NOTE: the ZooKeeper C client shell (cli_st and cli_mt) is meant as a
+example/sample of ZooKeeper C client API usage. It is not a full
+fledged client and not meant for production usage - see the Java
+client shell for a fully featured shell.
 
 You can test your client by running a zookeeper server (see
 instructions on the project wiki page on how to run it) and connecting

Modified: zookeeper/branches/branch-3.5/src/c/src/cli.c
URL: http://svn.apache.org/viewvc/zookeeper/branches/branch-3.5/src/c/src/cli.c?rev=1755855&r1=1755854&r2=1755855&view=diff
==============================================================================
--- zookeeper/branches/branch-3.5/src/c/src/cli.c (original)
+++ zookeeper/branches/branch-3.5/src/c/src/cli.c Wed Aug 10 20:55:43 2016
@@ -16,6 +16,14 @@
  * limitations under the License.
  */
 
+/**
+ * cli.c is a example/sample C client shell for ZooKeeper. It contains
+ * basic shell functionality which exercises some of the features of
+ * the ZooKeeper C client API. It is not a full fledged client and is
+ * not meant for production usage - see the Java client shell for a
+ * fully featured shell.
+ */
+
 #include <zookeeper.h>
 #include <proto.h>
 #include <stdlib.h>
@@ -679,7 +687,15 @@ int main(int argc, char **argv) {
     }
     if (argc > 2) {
       if(strncmp("cmd:",argv[2],4)==0){
-        strcpy(cmd,argv[2]+4);
+        size_t cmdlen = strlen(argv[2]);
+        if (cmdlen > sizeof(cmd)) {
+          fprintf(stderr,
+                  "Command length %zu exceeds max length of %zu\n",
+                  cmdlen,
+                  sizeof(cmd));
+          return 2;
+        }
+        strncpy(cmd, argv[2]+4, sizeof(cmd));
         batchMode=1;
         fprintf(stderr,"Batch mode: %s\n",cmd);
       }else{