summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-11-28 08:52:09 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-11-28 08:52:09 +0200
commit71d3b5d19d319a01cb07734c5c7b207abd57551f (patch)
treef2369dacdaf394ac6feaca69426d80f73d3d89d8
parentc8aaa4df1abb63c59bdaa06652a52270783cbe56 (diff)
Feeds: Abort parsing of feeds.txt if it's invalid
-rw-r--r--src/feeds.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/feeds.c b/src/feeds.c
index 47adb150..cccb81d5 100644
--- a/src/feeds.c
+++ b/src/feeds.c
@@ -393,16 +393,30 @@ static void load_Feeds_(iFeeds *d) {
393 break; 393 break;
394 } 394 }
395 case 2: { 395 case 2: {
396 /* TODO: All right, this could maybe use a bit more robust, structured
397 format. The code below is messy. */
396 const uint32_t feedId = strtoul(line.start, NULL, 16); 398 const uint32_t feedId = strtoul(line.start, NULL, 16);
397 if (!nextSplit_Rangecc(range_Block(src), "\n", &line)) break; 399 if (!nextSplit_Rangecc(range_Block(src), "\n", &line)) {
400 goto aborted;
401 }
398 const unsigned long long posted = strtoull(line.start, NULL, 10); 402 const unsigned long long posted = strtoull(line.start, NULL, 10);
399 if (posted == 0) break; 403 if (posted == 0) {
400 if (!nextSplit_Rangecc(range_Block(src), "\n", &line)) break; 404 goto aborted;
405 }
406 if (!nextSplit_Rangecc(range_Block(src), "\n", &line)) {
407 goto aborted;
408 }
401 const unsigned long long discovered = strtoull(line.start, NULL, 10); 409 const unsigned long long discovered = strtoull(line.start, NULL, 10);
402 if (discovered == 0) break; 410 if (discovered == 0) {
403 if (!nextSplit_Rangecc(range_Block(src), "\n", &line)) break; 411 goto aborted;
412 }
413 if (!nextSplit_Rangecc(range_Block(src), "\n", &line)) {
414 goto aborted;
415 }
404 const iRangecc urlRange = line; 416 const iRangecc urlRange = line;
405 if (!nextSplit_Rangecc(range_Block(src), "\n", &line)) break; 417 if (!nextSplit_Rangecc(range_Block(src), "\n", &line)) {
418 goto aborted;
419 }
406 const iRangecc titleRange = line; 420 const iRangecc titleRange = line;
407 iString *url = newRange_String(urlRange); 421 iString *url = newRange_String(urlRange);
408 iString *title = newRange_String(titleRange); 422 iString *title = newRange_String(titleRange);
@@ -423,6 +437,7 @@ static void load_Feeds_(iFeeds *d) {
423 } 437 }
424 } 438 }
425 } 439 }
440 aborted:
426 /* Cleanup. */ 441 /* Cleanup. */
427 delete_Block(src); 442 delete_Block(src);
428 iForEach(Hash, i, feeds) { 443 iForEach(Hash, i, feeds) {