summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2015-04-20 11:57:41 +0000
committerPierre Ossman <ossman@cendio.se>2015-04-20 11:57:41 +0000
commit07c952608503dabfe0e543304b8eaf806f1f8622 (patch)
tree2eb028706f4175a454f78de1e760968b83c9d39d
parenta08321a091500e50c72ad7beccace9331116171c (diff)
We cannot resize the selection buffer without also storing the new
length or we may get buffer overflows the next time we copy something. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10709 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
-rw-r--r--src/Fl_cocoa.mm34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm
index ebdfe779c..622b51e20 100644
--- a/src/Fl_cocoa.mm
+++ b/src/Fl_cocoa.mm
@@ -3447,6 +3447,14 @@ static void clipboard_check(void)
fl_trigger_clipboard_notify(1);
}
+static void resize_selection_buffer(int len, int clipboard) {
+ if (len <= fl_selection_buffer_length[clipboard])
+ return;
+ delete[] fl_selection_buffer[clipboard];
+ fl_selection_buffer[clipboard] = new char[len+100];
+ fl_selection_buffer_length[clipboard] = len+100;
+}
+
/*
* create a selection
* stuff: pointer to selected data
@@ -3455,11 +3463,7 @@ static void clipboard_check(void)
*/
void Fl::copy(const char *stuff, int len, int clipboard, const char *type) {
if (!stuff || len<0) return;
- if (len+1 > fl_selection_buffer_length[clipboard]) {
- delete[] fl_selection_buffer[clipboard];
- fl_selection_buffer[clipboard] = new char[len+100];
- fl_selection_buffer_length[clipboard] = len+100;
- }
+ resize_selection_buffer(len+1, clipboard);
memcpy(fl_selection_buffer[clipboard], stuff, len);
fl_selection_buffer[clipboard][len] = 0; // needed for direct paste
fl_selection_length[clipboard] = len;
@@ -3473,7 +3477,7 @@ void Fl::copy(const char *stuff, int len, int clipboard, const char *type) {
}
}
-static int get_plain_text_from_clipboard(char **buffer, int previous_length)
+static int get_plain_text_from_clipboard(int clipboard)
{
NSInteger length = 0;
NSPasteboard *clip = [NSPasteboard generalPasteboard];
@@ -3495,21 +3499,17 @@ static int get_plain_text_from_clipboard(char **buffer, int previous_length)
len = strlen(aux_c) + 1;
}
else len = [data length] + 1;
- if ( len >= previous_length ) {
- length = len;
- delete[] *buffer;
- *buffer = new char[len];
- }
+ resize_selection_buffer(len, clipboard);
if (![found isEqualToString:utf8_format]) {
- strcpy(*buffer, aux_c);
- free(aux_c);
+ strcpy(fl_selection_buffer[clipboard], aux_c);
+ free(aux_c);
}
else {
- [data getBytes:*buffer];
+ [data getBytes:fl_selection_buffer[clipboard]];
}
- (*buffer)[len - 1] = 0;
+ fl_selection_buffer[clipboard][len - 1] = 0;
length = len - 1;
- convert_crlf(*buffer, len - 1); // turn all \r characters into \n:
+ convert_crlf(fl_selection_buffer[clipboard], len - 1); // turn all \r characters into \n:
Fl::e_clipboard_type = Fl::clipboard_plain_text;
}
}
@@ -3605,7 +3605,7 @@ void Fl::paste(Fl_Widget &receiver, int clipboard, const char *type) {
if (clipboard) {
Fl::e_clipboard_type = "";
if (strcmp(type, Fl::clipboard_plain_text) == 0) {
- fl_selection_length[1] = get_plain_text_from_clipboard( &fl_selection_buffer[1], fl_selection_length[1]);
+ fl_selection_length[1] = get_plain_text_from_clipboard(1);
}
else if (strcmp(type, Fl::clipboard_image) == 0) {
Fl::e_clipboard_data = get_image_from_clipboard(&receiver);