| From 2bb205f8d9b657891e33536ee0906c76a7f72ac2 Mon Sep 17 00:00:00 2001 |
| From: Enrico Olivelli <eolivelli@apache.org> |
| Date: Sat, 9 Mar 2019 14:14:05 +0100 |
| Subject: [PATCH 1/4] ZOOKEEPER-3302 ZooKeeper C client does not compile on |
| Fedora 29 |
| |
| --- |
| zookeeper-client/zookeeper-client-c/src/cli.c | 6 +++--- |
| 1 file changed, 3 insertions(+), 3 deletions(-) |
| |
| diff --git a/zookeeper-client/zookeeper-client-c/src/cli.c b/zookeeper-client/zookeeper-client-c/src/cli.c |
| index 6ca4a415f9..c3c0ff8ea4 100644 |
| --- a/zookeeper-client/zookeeper-client-c/src/cli.c |
| +++ b/zookeeper-client/zookeeper-client-c/src/cli.c |
| @@ -678,15 +678,15 @@ int main(int argc, char **argv) { |
| } |
| if (argc > 2) { |
| if(strncmp("cmd:",argv[2],4)==0){ |
| - size_t cmdlen = strlen(argv[2]); |
| - if (cmdlen > sizeof(cmd)) { |
| + size_t cmdlen = strlen(argv[2]) - 4; |
| + 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)); |
| + memcpy(cmd, argv[2]+4, cmdlen); |
| batchMode=1; |
| fprintf(stderr,"Batch mode: %s\n",cmd); |
| }else{ |
| |
| From 0c909e3364fee601ec08f5e9d1fbef11637e749a Mon Sep 17 00:00:00 2001 |
| From: Enrico Olivelli <eolivelli@apache.org> |
| Date: Sun, 31 Mar 2019 14:47:27 +0200 |
| Subject: [PATCH 2/4] ZOOKEEPER-3302 ZooKeeper C client does not compile on |
| Fedora 29 |
| |
| --- |
| zookeeper-client/zookeeper-client-c/src/cli.c | 46 +++++++++++++++---- |
| 1 file changed, 36 insertions(+), 10 deletions(-) |
| |
| diff --git a/zookeeper-client/zookeeper-client-c/src/cli.c b/zookeeper-client/zookeeper-client-c/src/cli.c |
| index c3c0ff8ea4..96836dfeab 100644 |
| --- a/zookeeper-client/zookeeper-client-c/src/cli.c |
| +++ b/zookeeper-client/zookeeper-client-c/src/cli.c |
| @@ -649,6 +649,38 @@ void processline(char *line) { |
| zoo_add_auth(zh, line, ptr, ptr ? strlen(ptr) : 0, NULL, NULL); |
| } |
| } |
| +/* |
| + * Look for a command in the form 'cmd:command'. |
| + * Strips the prefix and copies the command in buf. |
| + * Returns 0 if the argument does not start with the prefix. |
| + * Returns -1 in case of error (command too long). |
| + * Returns 1 in case of success. |
| + * |
| + */ |
| +int handleBatchMode(char* arg, char* buf, size_t maxlen) { |
| + size_t cmdlen = strlen(arg); |
| + if (cmdlen < 4) { |
| + // too short |
| + return 0; |
| + } |
| + cmdlen -= 4; |
| + if(strncmp("cmd:", arg, 4) != 0){ |
| + return 0; |
| + } |
| + if (cmdlen >= maxlen) { |
| + fprintf(stderr, |
| + "Command length %zu exceeds max length of %zu\n", |
| + cmdlen, |
| + maxlen); |
| + return -1; |
| + } |
| + fprintf(stderr, |
| + "Command length %zu, max length of %zu\n", |
| + cmdlen, |
| + maxlen); |
| + memcpy(cmd, arg + 4, cmdlen); |
| + return 1; |
| +} |
| |
| int main(int argc, char **argv) { |
| #ifndef THREADED |
| @@ -677,18 +709,12 @@ int main(int argc, char **argv) { |
| return 2; |
| } |
| if (argc > 2) { |
| - if(strncmp("cmd:",argv[2],4)==0){ |
| - size_t cmdlen = strlen(argv[2]) - 4; |
| - if (cmdlen >= sizeof(cmd)) { |
| - fprintf(stderr, |
| - "Command length %zu exceeds max length of %zu\n", |
| - cmdlen, |
| - sizeof(cmd)); |
| + int batchModeRes = handleBatchMode(argv[2], cmd, sizeof(cmd)); |
| + if (batchModeRes == -1) { |
| return 2; |
| - } |
| - memcpy(cmd, argv[2]+4, cmdlen); |
| + } else if(batchModeRes == 1){ |
| batchMode=1; |
| - fprintf(stderr,"Batch mode: %s\n",cmd); |
| + fprintf(stderr,"Batch mode: '%s'\n",cmd); |
| }else{ |
| clientIdFile = argv[2]; |
| fh = fopen(clientIdFile, "r"); |
| |
| From 21cb65c1c8a4884358c5a1c75489a59635379d4c Mon Sep 17 00:00:00 2001 |
| From: Enrico Olivelli <eolivelli@apache.org> |
| Date: Sun, 31 Mar 2019 15:20:44 +0200 |
| Subject: [PATCH 3/4] Drop debug |
| |
| --- |
| zookeeper-client/zookeeper-client-c/src/cli.c | 4 ---- |
| 1 file changed, 4 deletions(-) |
| |
| diff --git a/zookeeper-client/zookeeper-client-c/src/cli.c b/zookeeper-client/zookeeper-client-c/src/cli.c |
| index 96836dfeab..bf8fcfa216 100644 |
| --- a/zookeeper-client/zookeeper-client-c/src/cli.c |
| +++ b/zookeeper-client/zookeeper-client-c/src/cli.c |
| @@ -674,10 +674,6 @@ int handleBatchMode(char* arg, char* buf, size_t maxlen) { |
| maxlen); |
| return -1; |
| } |
| - fprintf(stderr, |
| - "Command length %zu, max length of %zu\n", |
| - cmdlen, |
| - maxlen); |
| memcpy(cmd, arg + 4, cmdlen); |
| return 1; |
| } |
| |
| From 768ee50f657cbbaac008a6947fd4ac6fe4e6cefa Mon Sep 17 00:00:00 2001 |
| From: Enrico Olivelli <eolivelli@apache.org> |
| Date: Sun, 31 Mar 2019 15:35:33 +0200 |
| Subject: [PATCH 4/4] add comment |
| |
| --- |
| zookeeper-client/zookeeper-client-c/src/cli.c | 1 + |
| 1 file changed, 1 insertion(+) |
| |
| diff --git a/zookeeper-client/zookeeper-client-c/src/cli.c b/zookeeper-client/zookeeper-client-c/src/cli.c |
| index bf8fcfa216..6f443cd50e 100644 |
| --- a/zookeeper-client/zookeeper-client-c/src/cli.c |
| +++ b/zookeeper-client/zookeeper-client-c/src/cli.c |
| @@ -667,6 +667,7 @@ int handleBatchMode(char* arg, char* buf, size_t maxlen) { |
| if(strncmp("cmd:", arg, 4) != 0){ |
| return 0; |
| } |
| + // we must leave space for the NULL terminator |
| if (cmdlen >= maxlen) { |
| fprintf(stderr, |
| "Command length %zu exceeds max length of %zu\n", |