Changeset: 5c358ced2d8d for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=5c358ced2d8d
Modified Files:
        tools/merovingian/utils/control.c
Branch: Jan2014
Log Message:

Null-terminate buffer, and use returned length to null-terminate.


diffs (34 lines):

diff --git a/tools/merovingian/utils/control.c 
b/tools/merovingian/utils/control.c
--- a/tools/merovingian/utils/control.c
+++ b/tools/merovingian/utils/control.c
@@ -111,13 +111,14 @@ char* control_send(
                /* try reading length */
                len = recv(sock, rbuf, 2, 0);
                if (len == 2)
-                       len += recv(sock, rbuf + len, sizeof(rbuf) - len, 0);
+                       len += recv(sock, rbuf + len, sizeof(rbuf) - len - 1, 
0);
                /* perform login ritual */
                if (len <= 2) {
                        snprintf(sbuf, sizeof(sbuf), "no response from 
monetdbd");
                        close(sock);
                        return(strdup(sbuf));
                }
+               rbuf[len] = 0;
                /* we only understand merovingian:1 and :2 (backwards compat
                 * <=Aug2011) and mapi v9 on merovingian */
                if (strncmp(rbuf, "merovingian:1:", strlen("merovingian:1:")) 
== 0) {
@@ -296,12 +297,12 @@ char* control_send(
                if (fdin != NULL) {
                        /* stream.h is sooo broken :( */
                        memset(rbuf, '\0', sizeof(rbuf));
-                       if (mnstr_read_block(fdin, rbuf, sizeof(rbuf) - 1, 1) < 
0) {
+                       if ((len = mnstr_read_block(fdin, rbuf, sizeof(rbuf) - 
1, 1)) < 0) {
                                close_stream(fdout);
                                close_stream(fdin);
                                return(strdup("no response from monetdbd after 
login"));
                        }
-                       rbuf[strlen(rbuf) - 1] = '\0';
+                       rbuf[len - 1] = '\0';
                } else {
                        if ((len = recv(sock, rbuf, sizeof(rbuf), 0)) <= 0) {
                                close(sock);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to