From: Andrea Zagli Date: Thu, 18 Mar 2021 19:04:42 +0000 (+0100) Subject: In gdatetime_from_string must be checked if hour, minutes and seconds are valid values. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=e5f6ef4e86f4da7aea41fa844ce9888350fbf662;p=libzakutils In gdatetime_from_string must be checked if hour, minutes and seconds are valid values. --- diff --git a/src/datetime.c b/src/datetime.c index 1c3eb4a..629c615 100644 --- a/src/datetime.c +++ b/src/datetime.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015-2017 Andrea Zagli + * Copyright (C) 2015-2021 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -456,8 +456,11 @@ GDateTime } else if (g_strcmp0 (format_tokens[i], "%H") == 0) { - hour = strtol (str_tokens[i], NULL, 10); - if (hour > 23) + char *ptr; + + hour = strtol (str_tokens[i], &ptr, 10); + if ((ptr != NULL && g_strcmp0 (ptr, "") != 0) + || hour > 23) { error = TRUE; break; @@ -465,8 +468,11 @@ GDateTime } else if (g_strcmp0 (format_tokens[i], "%M") == 0) { - minute = strtol (str_tokens[i], NULL, 10); - if (minute > 59) + char *ptr; + + minute = strtol (str_tokens[i], &ptr, 10); + if ((ptr != NULL && g_strcmp0 (ptr, "") != 0) + || minute > 59) { error = TRUE; break; @@ -474,8 +480,11 @@ GDateTime } else if (g_strcmp0 (format_tokens[i], "%S") == 0) { - seconds = g_strtod (str_tokens[i], NULL); - if (seconds > 59.0) + char *ptr; + + seconds = g_strtod (str_tokens[i], &ptr); + if ((ptr != NULL && g_strcmp0 (ptr, "") != 0) + || seconds > 59.0) { error = TRUE; break;