TSAM-10606 strncat Buffer Overflow 03/101503/7 submit/tizen_3.0/20161201.130043
authorOleksander Kostenko <o.kostenko@samsung.com>
Thu, 1 Dec 2016 09:15:06 +0000 (11:15 +0200)
committerAndrey Klimenko <and.klimenko@samsung.com>
Thu, 1 Dec 2016 12:58:08 +0000 (04:58 -0800)
Change-Id: I8644b42937d4eee7f77499b3b9cd8db426124aa0
Signed-off-by: Oleksander Kostenko <o.kostenko@samsung.com>
src/set-schedule-info.c

index 8e6b4f0..da3c3bc 100755 (executable)
@@ -50,7 +50,9 @@ enum TimeFormat {
 #define BUTTON_TEXT_SIZE 512
 #define WEEK_BUTTON_SIZE 80
 #define DAY_MAX_LENGTH 80
-#define WEEK_MAX_STRING DAY_MAX_LENGTH * 7
+#define DAYS_IN_WEEK 7
+#define NUMBER_OF_SPACES 6
+#define WEEK_MAX_STRING DAY_MAX_LENGTH * DAYS_IN_WEEK + NUMBER_OF_SPACES + 1
 
 #define GREEN_TEXT_COLOR "<font_size=80><color=#b3b3b3>%s</color></font_size>"
 #define GREY_TEXT_COLOR "<font_size=80><color=#97e57b>%s</color></font_size>"
@@ -302,7 +304,9 @@ static void make_color_text(int dayCode, dnd_schedule_week_flag_e week_day, cons
        else
                snprintf(formattedDay, DAY_MAX_LENGTH, GREY_TEXT_MAIN, text);
 
-       strncat(outBuf, formattedDay, DAY_MAX_LENGTH);
+       strncat(outBuf, formattedDay, WEEK_MAX_STRING - strlen(outBuf) - 1);
+       if(week_day != DND_SCHEDULE_WEEK_FLAG_SUNDAY)
+               strncat(outBuf, " ", WEEK_MAX_STRING - strlen(outBuf) - 1);
 }
 
 int load_dnd_schedule_day()
@@ -323,17 +327,11 @@ const char *get_day_string(int dnd_schedule)
        buff[0] = 0;
 
        make_color_text(dnd_schedule, DND_SCHEDULE_WEEK_FLAG_MONDAY, APP_STRING("WDS_ALM_BUTTON_M_M_MONDAY_ABB"), buff);
-       strncat(buff, " ", WEEK_MAX_STRING);
        make_color_text(dnd_schedule, DND_SCHEDULE_WEEK_FLAG_TUESDAY, APP_STRING("WDS_ALM_BUTTON_T_M_TUESDAY_ABB"), buff);
-       strncat(buff, " ", WEEK_MAX_STRING);
        make_color_text(dnd_schedule, DND_SCHEDULE_WEEK_FLAG_WEDNESDAY, APP_STRING("WDS_ALM_BUTTON_W_M_WEDNESDAY_ABB"), buff);
-       strncat(buff, " ", WEEK_MAX_STRING);
        make_color_text(dnd_schedule, DND_SCHEDULE_WEEK_FLAG_THURSDAY, APP_STRING("WDS_ALM_BUTTON_T_M_THURSDAY_ABB"), buff);
-       strncat(buff, " ", WEEK_MAX_STRING);
        make_color_text(dnd_schedule, DND_SCHEDULE_WEEK_FLAG_FRIDAY, APP_STRING("WDS_ALM_BUTTON_F_M_FRIDAY_ABB"), buff);
-       strncat(buff, " ", WEEK_MAX_STRING);
        make_color_text(dnd_schedule, DND_SCHEDULE_WEEK_FLAG_SATURDAY, APP_STRING("WDS_ALM_BUTTON_S_M_SATURDAY_ABB"), buff);
-       strncat(buff, " ", WEEK_MAX_STRING);
        make_color_text(dnd_schedule, DND_SCHEDULE_WEEK_FLAG_SUNDAY, APP_STRING("WDS_ALM_BUTTON_S_M_SUNDAY_ABB"), buff);
        return buff;
 }