Changeset: 7d7e87343c9c for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7d7e87343c9c
Modified Files:
        tools/merovingian/ChangeLog.Dec2011
        tools/merovingian/client/monetdb.c
Branch: Dec2011
Log Message:

monetdb: avoid crash when using invalid properties with get command

Check properties first, such that warnings about invalid properties go
on top, then print, and silently skip invalid properties.
Fixes bug #2953.


diffs (64 lines):

diff --git a/tools/merovingian/ChangeLog.Dec2011 
b/tools/merovingian/ChangeLog.Dec2011
--- a/tools/merovingian/ChangeLog.Dec2011
+++ b/tools/merovingian/ChangeLog.Dec2011
@@ -1,6 +1,10 @@
 # ChangeLog file for sql/src/backends/monet5/merovingian
 # This file is updated with mchangelog
 
+* Tue Dec 27 2011 Fabian Groffen <[email protected]>
+- Fixed crash in monetdb when an invalid property was retrieved using
+  the get command, bug #2953.
+
 * Sat Oct  8 2011 Fabian Groffen <[email protected]>
 - monetdb get output is now grouped by database instead of by property
 
diff --git a/tools/merovingian/client/monetdb.c 
b/tools/merovingian/client/monetdb.c
--- a/tools/merovingian/client/monetdb.c
+++ b/tools/merovingian/client/monetdb.c
@@ -1209,7 +1209,6 @@ command_get(int argc, char *argv[])
        if (twidth < 6)
                twidth = 6;
        value = malloc(sizeof(char) * twidth + 1);
-       printf("     name          prop     source           value\n");
        stats = orig;
        while (stats != NULL) {
                e = control_send(&buf, mero_host, mero_port,
@@ -1245,9 +1244,25 @@ command_get(int argc, char *argv[])
                                }
                        }
                } else {
+                       /* check validity of properties before printing them */
+                       if (stats == orig) {
+                               snprintf(vbuf, sizeof(vbuf), "%s", property);
+                               buf = vbuf;
+                               while ((p = strtok(buf, ",")) != NULL) {
+                                       buf = NULL;
+                                       if (strcmp(p, "name") == 0)
+                                               continue;
+                                       kv = findConfKey(props, p);
+                                       if (kv == NULL)
+                                               fprintf(stderr, "get: no such 
property: %s\n", p);
+                               }
+                       }
                        snprintf(vbuf, sizeof(vbuf), "%s", property);
                }
                buf = vbuf;
+               /* print header after errors */
+               if (stats == orig)
+                       printf("     name          prop     source           
value\n");
 
                while ((p = strtok(buf, ",")) != NULL) {
                        buf = NULL;
@@ -1258,11 +1273,8 @@ command_get(int argc, char *argv[])
                                abbreviateString(value, stats->dbname, twidth);
                        } else {
                                kv = findConfKey(props, p);
-                               if (kv == NULL) {
-                                       fprintf(stderr, "get: no such property: 
%s\n", p);
-                                       stats = NULL;
+                               if (kv == NULL)
                                        continue;
-                               }
                                if (kv->val == NULL) {
                                        kv = findConfKey(defprops, p);
                                        source = "default";
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to