From: Hugo Villeneuve Date: Sun, 29 Mar 2020 23:33:03 +0000 (-0400) Subject: NULL terminate strncpy destination string X-Git-Url: http://gitweb.hugovil.com/?a=commitdiff_plain;p=dockapps%2Fwmnotify.git NULL terminate strncpy destination string --- diff --git a/src/configfile.c b/src/configfile.c index c9b9621..303ae16 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -271,8 +271,9 @@ static void ParseConfigurationFile(FILE *file) } } 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); @@ -282,13 +283,15 @@ static void ParseConfigurationFile(FILE *file) 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); - 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. */