summaryrefslogtreecommitdiff
path: root/src/mongo/shell
diff options
context:
space:
mode:
authorKevin Pulo <kevin.pulo@mongodb.com>2020-10-28 18:05:41 +1100
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-11-11 03:38:22 +0000
commitc575750f73b7a490a60919777dc49c45ec4f2e0c (patch)
tree3d36b399cda5f41a48b5721c82ca3e7ddd87c5b2 /src/mongo/shell
parent8a19a31598ffed4440df9c648ff457bfdf9e01e0 (diff)
downloadmongo-c575750f73b7a490a60919777dc49c45ec4f2e0c.tar.gz
SERVER-13980 warn when shell input lines are truncated
Diffstat (limited to 'src/mongo/shell')
-rw-r--r--src/mongo/shell/linenoise.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/mongo/shell/linenoise.cpp b/src/mongo/shell/linenoise.cpp
index 7c6865e4392..679578d133b 100644
--- a/src/mongo/shell/linenoise.cpp
+++ b/src/mongo/shell/linenoise.cpp
@@ -2611,6 +2611,11 @@ void linenoisePreloadBuffer(const char* preloadText) {
}
}
+static void printLongLineWarning(const char* context) {
+ printf("WARNING: %s truncated at %d bytes.\n", context, LINENOISE_MAX_LINE - 1);
+ fflush(stdout);
+}
+
/**
* linenoise is a readline replacement.
*
@@ -2644,6 +2649,9 @@ char* linenoise(const char* prompt) {
--len;
buf8[len] = '\0';
}
+ if (len == LINENOISE_MAX_LINE - 1) {
+ printLongLineWarning("input line");
+ }
return strdup(buf8.get()); // caller must free buffer
} else {
char* buf8 = strdup(preloadedBufferContents.c_str());
@@ -2665,6 +2673,9 @@ char* linenoise(const char* prompt) {
if (count == -1) {
return nullptr;
}
+ if (count == LINENOISE_MAX_LINE - 1) {
+ printLongLineWarning("input line");
+ }
size_t bufferSize = sizeof(UChar32) * ib.length() + 1;
unique_ptr<UChar8[]> buf8(new UChar8[bufferSize]);
copyString32to8(buf8.get(), buf32, bufferSize);
@@ -2682,6 +2693,9 @@ char* linenoise(const char* prompt) {
--count;
buf8[count] = '\0';
}
+ if (count == LINENOISE_MAX_LINE - 1) {
+ printLongLineWarning("input line");
+ }
return strdup(buf8.get()); // caller must free buffer
}
}
@@ -2823,6 +2837,7 @@ mongo::Status linenoiseHistoryLoad(const char* filename) {
return linenoiseFileError(mongo::ErrorCodes::FileOpenFailed, "fopen()", filename, ewd);
}
+ bool historyLinesTruncated = false;
char buf[LINENOISE_MAX_LINE];
while (fgets(buf, LINENOISE_MAX_LINE, fp) != nullptr) {
char* p = strchr(buf, '\r');
@@ -2833,9 +2848,16 @@ mongo::Status linenoiseHistoryLoad(const char* filename) {
*p = '\0';
}
if (p != buf) {
+ int count = strlen(buf);
+ if (count == LINENOISE_MAX_LINE - 1) {
+ historyLinesTruncated = true;
+ }
linenoiseHistoryAdd(buf);
}
}
+ if (historyLinesTruncated) {
+ printLongLineWarning("some history file lines were");
+ }
// fgets() returns NULL on error or EOF (with nothing read).
// So if we aren't EOF, it must have been an error.
if (!feof(fp)) {