main: strdup command line arguments that are modified
[project/uhttpd.git] / main.c
diff --git a/main.c b/main.c
index e53a311..38d023f 100644 (file)
--- a/main.c
+++ b/main.c
@@ -183,6 +183,13 @@ static void init_defaults_post(void)
        uh_index_add("index.htm");
        uh_index_add("default.html");
        uh_index_add("default.htm");
+
+       if (conf.cgi_prefix) {
+               char *str = malloc(strlen(conf.docroot) + strlen(conf.cgi_prefix) + 1);
+               strcpy(str, conf.docroot);
+               strcat(str, conf.cgi_prefix);
+               conf.cgi_docroot_path = str;
+       };
 }
 
 static void fixup_prefix(char *str)
@@ -242,6 +249,7 @@ int main(int argc, char **argv)
                        break;
 #endif
                case 'p':
+                       optarg = strdup(optarg);
                        bound += add_listener_arg(optarg, (ch == 's'));
                        break;
 
@@ -298,6 +306,7 @@ int main(int argc, char **argv)
                        break;
 
                case 'i':
+                       optarg = strdup(optarg);
                        port = strchr(optarg, '=');
                        if (optarg[0] != '.' || !port) {
                                fprintf(stderr, "Error: Invalid interpreter: %s\n",
@@ -330,6 +339,7 @@ int main(int argc, char **argv)
                        break;
 
                case 'd':
+                       optarg = strdup(optarg);
                        port = alloca(strlen(optarg) + 1);
                        if (!port)
                                return -1;
@@ -406,12 +416,6 @@ int main(int argc, char **argv)
        }
 
        uh_config_parse();
-       init_defaults_post();
-
-       if (!bound) {
-               fprintf(stderr, "Error: No sockets bound, unable to continue\n");
-               return 1;
-       }
 
        if (!conf.docroot) {
                if (!realpath(".", uh_buf)) {
@@ -421,6 +425,13 @@ int main(int argc, char **argv)
                conf.docroot = strdup(uh_buf);
        }
 
+       init_defaults_post();
+
+       if (!bound) {
+               fprintf(stderr, "Error: No sockets bound, unable to continue\n");
+               return 1;
+       }
+
 #ifdef HAVE_TLS
        if (n_tls) {
                if (!tls_crt || !tls_key) {