Author: mir3x Date: Mon Jan 16 13:42:06 2017 New Revision: 34834 URL: http://svn.gna.org/viewcvs/freeciv?rev=34834&view=rev Log: Qt client - fixed heap-use-after-free in optiondlg
See bug #25440 Modified: branches/S2_6/client/gui-qt/optiondlg.cpp branches/S2_6/client/gui-qt/optiondlg.h Modified: branches/S2_6/client/gui-qt/optiondlg.cpp URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/optiondlg.cpp?rev=34834&r1=34833&r2=34834&view=diff ============================================================================== --- branches/S2_6/client/gui-qt/optiondlg.cpp (original) +++ branches/S2_6/client/gui-qt/optiondlg.cpp Mon Jan 16 13:42:06 2017 @@ -225,8 +225,9 @@ /**************************************************************************** Return selected colors (for highlighting chat). ****************************************************************************/ -struct ft_color option_dialog::get_color(struct option *poption) { - +void option_dialog::get_color(struct option *poption, QByteArray &a1, + QByteArray &a2) +{ QPalette pal; QColor col1, col2; QWidget *w; @@ -239,8 +240,8 @@ but = w->findChild<QPushButton *>("text_background"); pal = but->palette(); col2 = pal.color(QPalette::Button); - - return ft_color_construct(col1.name().toUtf8().data(), col2.name().toUtf8().data()); + a1 = col1.name().toUtf8(); + a2 = col2.name().toUtf8(); } /**************************************************************************** @@ -248,6 +249,8 @@ ****************************************************************************/ void option_dialog::apply_options() { + QByteArray ba1, ba2; + options_iterate(curr_options, poption) { switch (option_type(poption)) { case OT_BOOLEAN: @@ -257,7 +260,7 @@ option_int_set(poption, get_int(poption)); break; case OT_STRING: - option_str_set(poption, get_string(poption)); + option_str_set(poption, get_string(poption).data()); break; case OT_ENUM: option_enum_set_int(poption, get_enum(poption)); @@ -266,10 +269,11 @@ option_bitwise_set(poption, get_bitwise(poption)); break; case OT_FONT: - option_font_set(poption, get_button_font(poption)); + option_font_set(poption, get_button_font(poption).data()); break; case OT_COLOR: - option_color_set(poption, get_color(poption)); + get_color(poption, ba1, ba2); + option_color_set(poption, ft_color_construct(ba1.data(), ba2.data())); break; case OT_VIDEO_MODE: log_error("Option type %s (%d) not supported yet.", @@ -383,17 +387,17 @@ /**************************************************************************** Get string for desired option from combobox or lineedit. ****************************************************************************/ -char *option_dialog::get_string(struct option *poption) +QByteArray option_dialog::get_string(struct option *poption) { QComboBox *cb; QLineEdit *le; if (option_str_values(poption) != NULL) { cb = reinterpret_cast<QComboBox *>(option_get_gui_data(poption)); - return cb->currentText().toUtf8().data(); + return cb->currentText().toUtf8(); } else { le = reinterpret_cast<QLineEdit *>(option_get_gui_data(poption)); - return le->displayText().toUtf8().data(); + return le->displayText().toUtf8(); } } @@ -812,14 +816,14 @@ /**************************************************************************** Get font from pushbutton. ****************************************************************************/ -char *option_dialog::get_button_font(struct option *poption) +QByteArray option_dialog::get_button_font(struct option *poption) { QPushButton *qp; QFont f; qp = reinterpret_cast<QPushButton *>(option_get_gui_data(poption)); f = qp->font(); - return f.toString().toUtf8().data(); + return f.toString().toUtf8(); } /**************************************************************************** Modified: branches/S2_6/client/gui-qt/optiondlg.h URL: http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/gui-qt/optiondlg.h?rev=34834&r1=34833&r2=34834&view=diff ============================================================================== --- branches/S2_6/client/gui-qt/optiondlg.h (original) +++ branches/S2_6/client/gui-qt/optiondlg.h Mon Jan 16 13:42:06 2017 @@ -65,12 +65,12 @@ void set_bitwise(struct option *poption, unsigned value); void set_color(struct option *poption, struct ft_color color); void set_font(struct option *poption, QString s); - struct ft_color get_color(struct option *poption); + void get_color(struct option *poption, QByteArray &a1, QByteArray &a2); bool get_bool(struct option *poption); int get_int(struct option *poption); - QFont get_font(struct option *poption); - char *get_button_font(struct option *poption); - char *get_string(struct option *poption); + QFont get_font(struct option *poption); + QByteArray get_button_font(struct option *poption); + QByteArray get_string(struct option *poption); int get_enum(struct option *poption); struct option* get_color_option(); unsigned get_bitwise(struct option *poption); _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits