From 5231c9e94b1e4dc5c4b37164ac6fa463fbedd81a Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Tue, 6 Jun 2017 17:49:40 +0200 Subject: [PATCH] Fix some defects detected by coverity scan --- src/algorithms/libs/rtklib/rtklib_rtkcmn.cc | 47 +++++++++++++-------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/src/algorithms/libs/rtklib/rtklib_rtkcmn.cc b/src/algorithms/libs/rtklib/rtklib_rtkcmn.cc index 252880b5b..ea6d31f5d 100644 --- a/src/algorithms/libs/rtklib/rtklib_rtkcmn.cc +++ b/src/algorithms/libs/rtklib/rtklib_rtkcmn.cc @@ -567,13 +567,20 @@ void setcodepri(int sys, int freq, const char *pri) trace(3, "setcodepri : sys=%d freq=%d pri=%s\n", sys, freq, pri); if (freq <= 0 || MAXFREQn; i++) { pcv = pcvs->pcv+i; @@ -2331,10 +2339,11 @@ pcv_t *searchpcv(int sat, const char *type, gtime_t time, if (pcv->te.time != 0 && timediff(pcv->te, time)<0.0) continue; return pcv; } - } + } else { - strcpy(buff, type); + if(strlen(type) < MAXANT +1 ) strcpy(buff, type); + else trace(1, "type array is too long"); for (p = strtok(buff, " "); p && n<2; p = strtok(NULL, " ")) types[n++] = p; if (n <= 0) return NULL; @@ -3013,7 +3022,8 @@ void traceopen(const char *file) reppath(file, path, time, "", ""); if (!*path || !(fp_trace = fopen(path, "w"))) fp_trace = stderr; - strcpy(file_trace, file); + if (strlen(file) < 1025) strcpy(file_trace, file); + else trace(1, "file array is too long"); tick_trace = tickget(); time_trace = time; initlock(&lock_trace); @@ -3228,7 +3238,8 @@ void createdir(const char *path) if (!(p = strrchr(buff, FILEPATHSEP))) return; *p = '\0'; - mkdir(buff, 0777); + if(mkdir(buff, 0777) == 0) {} + else trace(1, "Error creating folder"); } @@ -3966,10 +3977,10 @@ int rtk_uncompress(const char *file, char *uncfile) sprintf(cmd, "tar -C \"%s\" -xf \"%s\"", dir, tmpfile); if (execcmd(cmd)) { - if (stat) remove(tmpfile); + if (stat) if(remove(tmpfile) != 0) trace(1, "Error removing file"); return -1; } - if (stat) remove(tmpfile); + if (stat) if(remove(tmpfile) != 0) trace(1, "Error removing file"); stat = 1; } /* extract hatanaka-compressed file by cnx2rnx */ @@ -3983,10 +3994,10 @@ int rtk_uncompress(const char *file, char *uncfile) if (execcmd(cmd)) { remove(uncfile); - if (stat) remove(tmpfile); + if (stat) if(remove(tmpfile) != 0) trace(1, "Error removing file"); return -1; } - if (stat) remove(tmpfile); + if (stat) if(remove(tmpfile) != 0) trace(1, "Error removing file"); stat = 1; } trace(3, "rtk_uncompress: stat=%d\n", stat); @@ -4040,7 +4051,7 @@ int expath(const char *path, char *paths[], int nmax) { if (strcmp(paths[i], paths[j])>0) { - strcpy(tmp, paths[i]); + if(strlen(paths[i]) < 1025) strcpy(tmp, paths[i]); strcpy(paths[i], paths[j]); strcpy(paths[j], tmp); }