1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 11:07:45 +00:00

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

View file

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