Fixed panic if malformed 3rd party url is specified (#2817) · arduino/arduino-cli@e9092cc (original) (raw)
`@@ -534,9 +534,9 @@ func (s *arduinoCoreServerImpl) UpdateIndex(req *rpc.UpdateIndexRequest, stream
`
534
534
`return &cmderrors.InvalidInstanceError{}
`
535
535
` }
`
536
536
``
537
``
`-
report := func(indexURL *url.URL, status rpc.IndexUpdateReport_Status) *rpc.IndexUpdateReport {
`
``
537
`+
report := func(indexURL string, status rpc.IndexUpdateReport_Status) *rpc.IndexUpdateReport {
`
538
538
`return &rpc.IndexUpdateReport{
`
539
``
`-
IndexUrl: indexURL.String(),
`
``
539
`+
IndexUrl: indexURL,
`
540
540
`Status: status,
`
541
541
` }
`
542
542
` }
`
`@@ -564,7 +564,7 @@ func (s *arduinoCoreServerImpl) UpdateIndex(req *rpc.UpdateIndexRequest, stream
`
564
564
`downloadCB.Start(u, i18n.Tr("Downloading index: %s", u))
`
565
565
`downloadCB.End(false, msg)
`
566
566
`failed = true
`
567
``
`-
result.UpdatedIndexes = append(result.GetUpdatedIndexes(), report(URL, rpc.IndexUpdateReport_STATUS_FAILED))
`
``
567
`+
result.UpdatedIndexes = append(result.GetUpdatedIndexes(), report(u, rpc.IndexUpdateReport_STATUS_FAILED))
`
568
568
`continue
`
569
569
` }
`
570
570
``
`@@ -582,9 +582,9 @@ func (s *arduinoCoreServerImpl) UpdateIndex(req *rpc.UpdateIndexRequest, stream
`
582
582
`downloadCB.Start(u, i18n.Tr("Downloading index: %s", filepath.Base(URL.Path)))
`
583
583
`downloadCB.End(false, msg)
`
584
584
`failed = true
`
585
``
`-
result.UpdatedIndexes = append(result.GetUpdatedIndexes(), report(URL, rpc.IndexUpdateReport_STATUS_FAILED))
`
``
585
`+
result.UpdatedIndexes = append(result.GetUpdatedIndexes(), report(u, rpc.IndexUpdateReport_STATUS_FAILED))
`
586
586
` } else {
`
587
``
`-
result.UpdatedIndexes = append(result.GetUpdatedIndexes(), report(URL, rpc.IndexUpdateReport_STATUS_SKIPPED))
`
``
587
`+
result.UpdatedIndexes = append(result.GetUpdatedIndexes(), report(u, rpc.IndexUpdateReport_STATUS_SKIPPED))
`
588
588
` }
`
589
589
`continue
`
590
590
` }
`
`@@ -596,14 +596,14 @@ func (s *arduinoCoreServerImpl) UpdateIndex(req *rpc.UpdateIndexRequest, stream
`
596
596
`downloadCB.Start(u, i18n.Tr("Downloading index: %s", filepath.Base(URL.Path)))
`
597
597
`downloadCB.End(false, i18n.Tr("Invalid index URL: %s", err))
`
598
598
`failed = true
`
599
``
`-
result.UpdatedIndexes = append(result.GetUpdatedIndexes(), report(URL, rpc.IndexUpdateReport_STATUS_FAILED))
`
``
599
`+
result.UpdatedIndexes = append(result.GetUpdatedIndexes(), report(u, rpc.IndexUpdateReport_STATUS_FAILED))
`
600
600
`continue
`
601
601
` }
`
602
602
`indexFile := indexpath.Join(indexFileName)
`
603
603
`if info, err := indexFile.Stat(); err == nil {
`
604
604
`ageSecs := int64(time.Since(info.ModTime()).Seconds())
`
605
605
`if ageSecs < req.GetUpdateIfOlderThanSecs() {
`
606
``
`-
result.UpdatedIndexes = append(result.GetUpdatedIndexes(), report(URL, rpc.IndexUpdateReport_STATUS_ALREADY_UP_TO_DATE))
`
``
606
`+
result.UpdatedIndexes = append(result.GetUpdatedIndexes(), report(u, rpc.IndexUpdateReport_STATUS_ALREADY_UP_TO_DATE))
`
607
607
`continue
`
608
608
` }
`
609
609
` }
`
`@@ -622,9 +622,9 @@ func (s *arduinoCoreServerImpl) UpdateIndex(req *rpc.UpdateIndexRequest, stream
`
622
622
` }
`
623
623
`if err := indexResource.Download(stream.Context(), indexpath, downloadCB, config); err != nil {
`
624
624
`failed = true
`
625
``
`-
result.UpdatedIndexes = append(result.GetUpdatedIndexes(), report(URL, rpc.IndexUpdateReport_STATUS_FAILED))
`
``
625
`+
result.UpdatedIndexes = append(result.GetUpdatedIndexes(), report(u, rpc.IndexUpdateReport_STATUS_FAILED))
`
626
626
` } else {
`
627
``
`-
result.UpdatedIndexes = append(result.GetUpdatedIndexes(), report(URL, rpc.IndexUpdateReport_STATUS_UPDATED))
`
``
627
`+
result.UpdatedIndexes = append(result.GetUpdatedIndexes(), report(u, rpc.IndexUpdateReport_STATUS_UPDATED))
`
628
628
` }
`
629
629
` }
`
630
630
`syncSend.Send(&rpc.UpdateIndexResponse{
`