[PATCH] str-format: Fix month name parsing in BSD timestamps
When parsing the month name in scan_month_abbrev(), use memcmp() in all cases to compare only the first three chars. Using strcmp() will always result in us taking the false branch on well-formed timestamps, as it will scan past the 3-char length. Signed-off-by: Gergely Nagy <algernon@madhouse-project.org> --- lib/str-format.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/str-format.c b/lib/str-format.c index 6c974ba..9011461 100644 --- a/lib/str-format.c +++ b/lib/str-format.c @@ -200,19 +200,19 @@ scan_month_abbrev(const gchar **buf, gint *left, gint *mon) *mon = 7; break; case 'S': - if (strcmp(*buf, "Sep") == 0) + if (memcmp(*buf, "Sep", 3) == 0) *mon = 8; break; case 'O': - if (strcmp(*buf, "Oct") == 0) + if (memcmp(*buf, "Oct", 3) == 0) *mon = 9; break; case 'N': - if (strcmp(*buf, "Nov") == 0) + if (memcmp(*buf, "Nov",3 ) == 0) *mon = 10; break; case 'D': - if (strcmp(*buf, "Dec") == 0) + if (memcmp(*buf, "Dec", 3) == 0) *mon = 11; break; default: -- 1.7.5.4
Hi, Thanks, I don't see how I could use memcmp() for most cases, except a few. Probably something distracted me in the middle. However, this means that all timestamps in September, October, November and December will be parsed incorrectly. Good catch. Applied to 3.3. On Sat, 2011-09-03 at 00:39 +0200, Gergely Nagy wrote:
When parsing the month name in scan_month_abbrev(), use memcmp() in all cases to compare only the first three chars. Using strcmp() will always result in us taking the false branch on well-formed timestamps, as it will scan past the 3-char length.
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org> --- lib/str-format.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/lib/str-format.c b/lib/str-format.c index 6c974ba..9011461 100644 --- a/lib/str-format.c +++ b/lib/str-format.c @@ -200,19 +200,19 @@ scan_month_abbrev(const gchar **buf, gint *left, gint *mon) *mon = 7; break; case 'S': - if (strcmp(*buf, "Sep") == 0) + if (memcmp(*buf, "Sep", 3) == 0) *mon = 8; break; case 'O': - if (strcmp(*buf, "Oct") == 0) + if (memcmp(*buf, "Oct", 3) == 0) *mon = 9; break; case 'N': - if (strcmp(*buf, "Nov") == 0) + if (memcmp(*buf, "Nov",3 ) == 0) *mon = 10; break; case 'D': - if (strcmp(*buf, "Dec") == 0) + if (memcmp(*buf, "Dec", 3) == 0) *mon = 11; break; default:
-- Bazsi
On Sat, 2011-09-03 at 19:53 +0200, Balazs Scheidler wrote:
Hi,
Thanks, I don't see how I could use memcmp() for most cases, except a few. Probably something distracted me in the middle.
However, this means that all timestamps in September, October, November and December will be parsed incorrectly.
Good catch. Applied to 3.3.
Thinking a little bit further, this will bite anyone who uses 3.3, so anyone who is running that in production should consider an upgrade. Especially as I've fixed the memory leaks now. -- Bazsi
participants (2)
-
Balazs Scheidler
-
Gergely Nagy