]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
libimcv: Make sure the first argument to sscanf() is null-terminated
authorTobias Brunner <tobias@strongswan.org>
Tue, 23 May 2017 10:24:01 +0000 (12:24 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 23 May 2017 16:29:13 +0000 (18:29 +0200)
src/libimcv/ietf/ietf_attr_op_status.c
src/libimcv/tcg/pts/tcg_pts_attr_simple_comp_evid.c

index f04c89b96d088271ca2df11ee5ccb6ce4c4eb114..1f813b3c6673ad29fea479db8dfd6eb106eebbe7 100644 (file)
@@ -170,6 +170,7 @@ METHOD(pa_tnc_attr_t, process, status_t,
        chunk_t last_use;
        uint16_t reserved;
        struct tm t;
+       char buf[BUF_LEN];
 
        *offset = 0;
 
@@ -208,7 +209,8 @@ METHOD(pa_tnc_attr_t, process, status_t,
        *offset = 4;
 
        /* Conversion from RFC 3339 ASCII string to time_t */
-       if (sscanf(last_use.ptr, "%4d-%2d-%2dT%2d:%2d:%2dZ", &t.tm_year, &t.tm_mon,
+       snprintf(buf, sizeof(buf), "%.*s", (int)last_use.len, last_use.ptr);
+       if (sscanf(buf, "%4d-%2d-%2dT%2d:%2d:%2dZ", &t.tm_year, &t.tm_mon,
                           &t.tm_mday, &t.tm_hour, &t.tm_min, &t.tm_sec) != 6)
        {
                DBG1(DBG_TNC, "invalid last_use time format in IETF operational status");
index c249ca1516a037f79eb2b01b0615b0ec43e49620..9438fa06281cb0c17579d0c75057e5c19eeaba1f 100644 (file)
@@ -263,13 +263,15 @@ bool measurement_time_from_utc(time_t *measurement_time, chunk_t utc_time)
 {
        int tm_year, tm_mon, tm_day, tm_days, tm_hour, tm_min, tm_sec, tm_secs;
        int tm_leap_4, tm_leap_100, tm_leap_400, tm_leap;
+       char buf[BUF_LEN];
 
        if (memeq(utc_undefined_time_str, utc_time.ptr, utc_time.len))
        {
                *measurement_time = 0;
                return TRUE;
        }
-       if (sscanf(utc_time.ptr, "%4d-%2d-%2dT%2d:%2d:%2dZ",
+       snprintf(buf, sizeof(buf), "%.*s", (int)utc_time.len, utc_time.ptr);
+       if (sscanf(buf, "%4d-%2d-%2dT%2d:%2d:%2dZ",
                &tm_year, &tm_mon, &tm_day, &tm_hour, &tm_min, &tm_sec) != 6)
        {
                return FALSE;