paste: Don't read past clipboard data buffer size

ByteBuffer is not null-terminated (anymore), this is another one of
those bugs.
Also use the new format functions while we're here.

Fixes #4558.
This commit is contained in:
Linus Groh 2020-12-27 00:59:18 +01:00 committed by Andreas Kling
parent 74fa894994
commit 4395e1b240
Notes: sideshowbarker 2024-07-19 00:34:33 +09:00

View File

@ -28,7 +28,6 @@
#include <LibCore/ArgsParser.h>
#include <LibGUI/Application.h>
#include <LibGUI/Clipboard.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[])
@ -48,17 +47,17 @@ int main(int argc, char* argv[])
auto data_and_type = clipboard.data_and_type();
if (data_and_type.mime_type.is_null()) {
fprintf(stderr, "Nothing copied\n");
warnln("Nothing copied");
return 1;
}
if (!print_type) {
printf("%s", data_and_type.data.data());
out("{}", StringView(data_and_type.data));
// Append a newline to text contents, unless the caller says otherwise.
if (data_and_type.mime_type.starts_with("text/") && !no_newline)
putchar('\n');
outln();
} else {
printf("%s\n", data_and_type.mime_type.characters());
outln("{}", data_and_type.mime_type);
}
return 0;