From 41511cbc5f51a48fbe97b24993c7837b8f583ea3 Mon Sep 17 00:00:00 2001 From: Dylan Van Assche Date: Tue, 7 Sep 2021 07:32:55 +0200 Subject: [PATCH] gnss: truncate temporary file before download A temporary file is used to download the GNSS assistance data. It's created and truncated at initialization, but not truncated when a re-upload is necessary (when data expires). This causes to corrupt the GNSS assistance data if the new downloaded data is smaller than the previous download. --- src/gnss.c | 2 ++ src/gnss.h | 1 + 2 files changed, 3 insertions(+) diff --git a/src/gnss.c b/src/gnss.c index aa1bb6f..2116c18 100644 --- a/src/gnss.c +++ b/src/gnss.c @@ -191,6 +191,8 @@ static void fetch_assistance_data(struct EG25Manager *manager) /* Fetch assistance data with curl */ tmp_file = fdopen(manager->gnss_assistance_fd, "wb+"); + lseek(manager->gnss_assistance_fd, 0, SEEK_SET); + ftruncate(manager->gnss_assistance_fd, 0); url = g_strconcat(manager->gnss_assistance_url, "/", manager->gnss_assistance_file, NULL); curl = curl_easy_init(); diff --git a/src/gnss.h b/src/gnss.h index 1b49403..c3b5553 100644 --- a/src/gnss.h +++ b/src/gnss.h @@ -7,6 +7,7 @@ #pragma once #include +#include #include #include "manager.h"