From f5617a4de54c313580fe39562f0d32e5c95f5212 Mon Sep 17 00:00:00 2001
From: rpm-build <rpm-build>
Date: Thu, 14 Sep 2017 01:05:53 +0200
Subject: [PATCH] Allow having both options and config file on command line
---
src/ftpd.c | 2 +-
src/simpleconf.c | 23 +++++++++++++++++++++--
2 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/src/ftpd.c b/src/ftpd.c
index c5edac5..b13afc0 100644
--- a/src/ftpd.c
+++ b/src/ftpd.c
@@ -5589,7 +5589,7 @@ int pureftpd_start(int argc, char *argv[], const char *home_directory_)
#endif
#ifndef MINIMAL
- if (argc == 2 && *argv[1] != '-' &&
+ if (argc >= 2 && *argv[1] != '-' &&
sc_build_command_line_from_file(argv[1], NULL, simpleconf_options,
(sizeof simpleconf_options) /
(sizeof simpleconf_options[0]),
diff --git a/src/simpleconf.c b/src/simpleconf.c
index f296f54..505aee1 100644
--- a/src/simpleconf.c
+++ b/src/simpleconf.c
@@ -674,9 +674,10 @@ sc_build_command_line_from_file(const char *file_name,
{
char **argv = NULL;
int argc = 0;
+ char **argv_tmp = NULL;
+ char *arg = NULL;
+ int i;
- *argc_p = 0;
- *argv_p = NULL;
if ((argv = malloc(sizeof *argv)) == NULL ||
(app_name = strdup(app_name)) == NULL) {
sc_argv_free(argc, argv);
@@ -689,6 +690,24 @@ sc_build_command_line_from_file(const char *file_name,
sc_argv_free(argc, argv);
return -1;
}
+
+ for (i = 2; i < *argc_p; ++i) {
+ ++argc;
+ arg = strdup((*argv_p)[i]);
+ if (arg == NULL) {
+ return -1;
+ }
+ if ((argv_tmp = realloc(argv, (sizeof arg) *
+ ((size_t) argc + 1))) == NULL) {
+ return -1;
+ }
+ argv = argv_tmp;
+ argv[argc - 1] = arg;
+ }
+ if (*argc_p > 2) {
+ argv[argc] = NULL;
+ }
+
*argc_p = argc;
*argv_p = argv;
--
2.9.5