Changeset 552c8a5


Ignore:
Timestamp:
2015-02-22T21:19:21Z (10 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
91f06e5
Parents:
273949d
git-author:
dequis <dx@…> (22-02-15 05:00:37)
git-committer:
dequis <dx@…> (22-02-15 21:19:21)
Message:

twitter_parse_id function, with better error handling than sscanf()

Fixes issues such as parsing "reply eo" as replying to "0e",
as reported by torrancew

File:
1 edited

Legend:

Unmodified
Added
Removed
  • protocols/twitter/twitter.c

    r273949d r552c8a5  
    852852}
    853853
     854/* Parses a decimal or hex tweet ID, handling errors by returning 0 */
     855static guint64 twitter_parse_id(char *string, int base)
     856{
     857        guint64 parsed;
     858        char *endptr;
     859
     860        errno = 0;
     861        parsed = g_ascii_strtoull(string, &endptr, base);
     862        if (errno || endptr == string || *endptr == '\0') {
     863                return 0;
     864        }
     865        return parsed;
     866}
     867
    854868/** Convert the given bitlbee tweet ID, bitlbee username, or twitter tweet ID
    855869 *  into a twitter tweet ID.
     
    879893                        arg++;
    880894                }
    881                 if (sscanf(arg, "%" G_GINT64_MODIFIER "x", &id) == 1 &&
    882                     id < TWITTER_LOG_LENGTH) {
     895                if ((id = twitter_parse_id(arg, 16)) && id < TWITTER_LOG_LENGTH) {
    883896                        bu = td->log[id].bu;
    884897                        id = td->log[id].id;
     
    887900                                bu = NULL;
    888901                        }
    889                 } else if (sscanf(arg, "%" G_GINT64_MODIFIER "d", &id) == 1) {
     902                } else if ((id = twitter_parse_id(arg, 10))) {
    890903                        /* Allow normal tweet IDs as well; not a very useful
    891904                           feature but it's always been there. Just ignore
Note: See TracChangeset for help on using the changeset viewer.