From 8b91a1f60f5d27c91d5a9939236e6078a090ef92 Mon Sep 17 00:00:00 2001 From: dequis Date: Fri, 6 Mar 2015 05:27:06 -0300 Subject: twitter: Fix twitter_parse_id to accept 00 as a valid tweet Also fix the endptr condition which was backwards and resulted in every tweet id getting rejected, but you didn't see that one, this commit really is about the tweet id 00 which is the most important tweet id. --- protocols/twitter/twitter.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'protocols/twitter/twitter.c') diff --git a/protocols/twitter/twitter.c b/protocols/twitter/twitter.c index 891d07a6..95384573 100644 --- a/protocols/twitter/twitter.c +++ b/protocols/twitter/twitter.c @@ -851,18 +851,19 @@ static void twitter_buddy_data_free(struct bee_user *bu) g_free(bu->data); } -/* Parses a decimal or hex tweet ID, handling errors by returning 0 */ -static guint64 twitter_parse_id(char *string, int base) +/* Parses a decimal or hex tweet ID, returns TRUE on success */ +static gboolean twitter_parse_id(char *string, int base, guint64 *id) { guint64 parsed; char *endptr; errno = 0; parsed = g_ascii_strtoull(string, &endptr, base); - if (errno || endptr == string || *endptr == '\0') { - return 0; + if (errno || endptr == string || *endptr != '\0') { + return FALSE; } - return parsed; + *id = parsed; + return TRUE; } /** Convert the given bitlbee tweet ID, bitlbee username, or twitter tweet ID @@ -892,14 +893,14 @@ static guint64 twitter_message_id_from_command_arg(struct im_connection *ic, cha if (arg[0] == '#') { arg++; } - if ((id = twitter_parse_id(arg, 16)) && id < TWITTER_LOG_LENGTH) { + if (twitter_parse_id(arg, 16, &id) && id < TWITTER_LOG_LENGTH) { bu = td->log[id].bu; id = td->log[id].id; /* Beware of dangling pointers! */ if (!g_slist_find(ic->bee->users, bu)) { bu = NULL; } - } else if ((id = twitter_parse_id(arg, 10))) { + } else if (twitter_parse_id(arg, 10, &id)) { /* Allow normal tweet IDs as well; not a very useful feature but it's always been there. Just ignore very low IDs to avoid accidents. */ -- cgit v1.2.3