summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib/cmndline.cc
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg/contrib/cmndline.cc')
-rw-r--r--apt-pkg/contrib/cmndline.cc14
1 files changed, 10 insertions, 4 deletions
diff --git a/apt-pkg/contrib/cmndline.cc b/apt-pkg/contrib/cmndline.cc
index c8a6e2787..029ec3060 100644
--- a/apt-pkg/contrib/cmndline.cc
+++ b/apt-pkg/contrib/cmndline.cc
@@ -402,21 +402,27 @@ void CommandLine::SaveInConfig(unsigned int const &argc, char const * const * co
bool closeQuote = false;
for (unsigned int i = 0; i < argc && length < sizeof(cmdline); ++i, ++length)
{
- for (unsigned int j = 0; argv[i][j] != '\0' && length < sizeof(cmdline)-1; ++j, ++length)
+ for (unsigned int j = 0; argv[i][j] != '\0' && length < sizeof(cmdline)-2; ++j)
{
- cmdline[length] = argv[i][j];
+ // we can't really sensibly deal with quoting so skip it
+ if (strchr("\"\'\r\n", argv[i][j]) != nullptr)
+ continue;
+ cmdline[length++] = argv[i][j];
if (lastWasOption == true && argv[i][j] == '=')
{
// That is possibly an option: Quote it if it includes spaces,
// the benefit is that this will eliminate also most false positives
const char* c = strchr(&argv[i][j+1], ' ');
if (c == NULL) continue;
- cmdline[++length] = '"';
+ cmdline[length++] = '\'';
closeQuote = true;
}
}
if (closeQuote == true)
- cmdline[length++] = '"';
+ {
+ cmdline[length++] = '\'';
+ closeQuote = false;
+ }
// Problem: detects also --hello
if (cmdline[length-1] == 'o')
lastWasOption = true;