summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Pamment <apamment@yandex.com>2018-12-21 19:32:23 +1000
committerAndrew Pamment <apamment@yandex.com>2018-12-21 19:32:23 +1000
commit4fed7420beaa04489d4666af737ccfa64dcc8229 (patch)
tree02aa8b3a62b451c7fcaf4667e618190064d9ec80
parent804e05ae78243f24c88225bd33e312ff428c0341 (diff)
safe_atoi in qwknet
-rw-r--r--utils/qwknet/qwktoss.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/utils/qwknet/qwktoss.c b/utils/qwknet/qwktoss.c
index 270b77e..ba58c31 100644
--- a/utils/qwknet/qwktoss.c
+++ b/utils/qwknet/qwktoss.c
@@ -45,6 +45,18 @@ int msg_count = 0;
struct msg_bases **msgbases;
int msgbasecount = 0;
+static int safe_atoi(const char *str, int len) {
+ int ret = 0;
+
+ for (int i=0;i<len;i++) {
+ if (str[i] < '0' || str[i] > '9') {
+ break;
+ }
+ ret = ret * 10 + (str[i] - '0');
+ }
+ return ret;
+}
+
static int open_sq3_database(const char *path, sqlite3 **db) {
const char *create_sql = "CREATE TABLE IF NOT EXISTS msgs(id INTEGER PRIMARY KEY, sender TEXT, recipient TEXT, subject TEXT, date INTEGER, mattribs INTEGER, daddress TEXT, oaddress TEXT, msgid TEXT, replyid TEXT, body TEXT);";
const char *create_sql2 = "CREATE TABLE IF NOT EXISTS lastread(userid INTEGER, messageid INTEGER);";
@@ -318,7 +330,7 @@ int process_msgs_dat(char *msgsdat) {
break;
}
- msgrecs = atoi(qhdr.Msgrecs);
+ msgrecs = safe_atoi(qhdr.Msgrecs, 6);
msgbody = (char *)malloc((msgrecs * 128) + 1);
memset(msgbody, 0, (msgrecs * 128) + 1);
for (i=1;i<msgrecs;i++) {