浏览代码

Resolves: 328741
Summary: Ensure that we NULL terminate strings properly when processing config file settings.

Nathan Kinder 18 年之前
父节点
当前提交
6e0b12928e
共有 1 个文件被更改,包括 4 次插入0 次删除
  1. 4 0
      ldap/servers/snmp/main.c

+ 4 - 0
ldap/servers/snmp/main.c

@@ -264,6 +264,10 @@ load_config(char *conf_path)
             if ((pidfile = malloc((p - conf_path) +
             if ((pidfile = malloc((p - conf_path) +
                                    strlen(LDAP_AGENT_PIDFILE) + 2)) != NULL) {
                                    strlen(LDAP_AGENT_PIDFILE) + 2)) != NULL) {
                 strncpy(pidfile, conf_path, (p - conf_path + 1));
                 strncpy(pidfile, conf_path, (p - conf_path + 1));
+                /* The above will likely not be NULL terminated, but we need to
+                 * be sure that we're properly NULL terminated for the below
+                 * strcat() to work properly. */
+                pidfile[(p - conf_path + 2)] = (char)0;
                 strcat(pidfile, LDAP_AGENT_PIDFILE);
                 strcat(pidfile, LDAP_AGENT_PIDFILE);
                 pidfile[((p - conf_path) + strlen(LDAP_AGENT_PIDFILE) + 1)] = (char)0;
                 pidfile[((p - conf_path) + strlen(LDAP_AGENT_PIDFILE) + 1)] = (char)0;
             } else {
             } else {