Changeset: 28af495bf842 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/28af495bf842
Modified Files:
        tools/merovingian/client/monetdb.c
Branch: Jun2023
Log Message:

Check snprintf result so that we don't need dirty tricks to compile.


diffs (31 lines):

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
@@ -2509,8 +2509,11 @@ main(int argc, char *argv[])
                if (mero_host == NULL)
                        mero_host = "/tmp";
                /* first try the port given (or else its default) */
-               snprintf(buf, sizeof(buf), "%s/.s.merovingian.%d",
-                        mero_host, mero_port == -1 ? MAPI_PORT : mero_port);
+               if (snprintf(buf, sizeof(buf), "%s/.s.merovingian.%d",
+                                        mero_host, mero_port == -1 ? MAPI_PORT 
: mero_port) >= (int) sizeof(buf)) {
+                       fprintf(stderr, "monetdb: directory name too long\n");
+                       exit(1);
+               }
                if ((err = control_ping(buf, -1, NULL)) == NULL) {
                        mero_host = buf;
                } else {
@@ -2530,9 +2533,11 @@ main(int argc, char *argv[])
                                while ((e = readdir(d)) != NULL) {
                                        if (strncmp(e->d_name, 
".s.merovingian.", 15) != 0)
                                                continue;
-                                       snprintf(buf, sizeof(buf), "%s/%s", 
mero_host, e->d_name);
-                                       if (stat(buf, &s) == -1)
+                                       if (snprintf(buf, sizeof(buf), "%s/%s", 
mero_host, e->d_name) >= (int) sizeof(buf) ||
+                                               stat(buf, &s) == -1) {
+                                               /* too long or doesn't exist */
                                                continue;
+                                       }
                                        if (S_ISSOCK(s.st_mode)) {
                                                char *nerr;
                                                if ((nerr = control_ping(buf, 
-1, NULL)) == NULL) {
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to