NULL terminate strncpy destination string master
authorHugo Villeneuve <hugo@hugovil.com>
Sun, 29 Mar 2020 23:33:03 +0000 (19:33 -0400)
committerHugo Villeneuve <hugo@hugovil.com>
Sun, 29 Mar 2020 23:33:03 +0000 (19:33 -0400)
src/configfile.c

index c9b9621..303ae16 100644 (file)
@@ -271,8 +271,9 @@ static void ParseConfigurationFile(FILE *file)
                        }
                } else if (STREQ(token, "server")) {
                        token = GetArguments("server", true);
                        }
                } else if (STREQ(token, "server")) {
                        token = GetArguments("server", true);
-                       strncpy(wmnotify_infos.server_name, token,
-                               MAX_STR_LEN);
+                       strncpy(wmnotify_infos.server_name, token, MAX_STR_LEN - 1);
+                        wmnotify_infos.server_name[
+                            sizeof(wmnotify_infos.server_name) - 1] = '\0';
                        server_found = true;
                } else if (STREQ(token, "port")) {
                        token = GetArguments("port", true);
                        server_found = true;
                } else if (STREQ(token, "port")) {
                        token = GetArguments("port", true);
@@ -282,13 +283,15 @@ static void ParseConfigurationFile(FILE *file)
 
                else if (STREQ(token, "username")) {
                        token = GetArguments("username", true);
 
                else if (STREQ(token, "username")) {
                        token = GetArguments("username", true);
-                       strncpy(wmnotify_infos.username, token,
-                               MAX_STR_LEN);
+                       strncpy(wmnotify_infos.username, token, MAX_STR_LEN - 1);
+                        wmnotify_infos.username[
+                            sizeof(wmnotify_infos.username) - 1] = '\0';
                        username_found = true;
                } else if (STREQ(token, "password")) {
                        token = GetArguments("password", true);
                        username_found = true;
                } else if (STREQ(token, "password")) {
                        token = GetArguments("password", true);
-                       strncpy(wmnotify_infos.password, token,
-                               MAX_STR_LEN);
+                       strncpy(wmnotify_infos.password, token, MAX_STR_LEN - 1);
+                        wmnotify_infos.password[
+                            sizeof(wmnotify_infos.password) - 1] = '\0';
                        password_found = true;
                } else if (STREQ(token, "mailcheckdelay")) {
                        int delay;      /* delay in minutes. */
                        password_found = true;
                } else if (STREQ(token, "mailcheckdelay")) {
                        int delay;      /* delay in minutes. */