Ensure that buffers are always terminated

This commit is contained in:
Carles Fernandez 2019-08-13 20:49:48 +02:00
parent 47ded00812
commit bbaa9310ec
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
4 changed files with 31 additions and 1 deletions

View File

@ -674,30 +674,37 @@ void setcodepri(int sys, int freq, const char *pri)
if (sys & SYS_GPS)
{
std::strncpy(codepris[0][freq - 1], pri, 16);
codepris[0][freq - 1][15] = '\0';
}
if (sys & SYS_GLO)
{
std::strncpy(codepris[1][freq - 1], pri, 16);
codepris[1][freq - 1][15] = '\0';
}
if (sys & SYS_GAL)
{
std::strncpy(codepris[2][freq - 1], pri, 16);
codepris[2][freq - 1][15] = '\0';
}
if (sys & SYS_QZS)
{
std::strncpy(codepris[3][freq - 1], pri, 16);
codepris[3][freq - 1][15] = '\0';
}
if (sys & SYS_SBS)
{
std::strncpy(codepris[4][freq - 1], pri, 16);
codepris[4][freq - 1][15] = '\0';
}
if (sys & SYS_BDS)
{
std::strncpy(codepris[5][freq - 1], pri, 16);
codepris[5][freq - 1][15] = '\0';
}
if (sys & SYS_IRN)
{
std::strncpy(codepris[6][freq - 1], pri, 16);
codepris[6][freq - 1][15] = '\0';
}
}
else
@ -2982,6 +2989,7 @@ pcv_t *searchpcv(int sat, const char *type, gtime_t time,
if (strlen(type) < MAXANT + 1)
{
std::strncpy(buff, type, MAXANT);
buff[MAXANT - 1] = '\0';
}
else
{
@ -3873,6 +3881,7 @@ void traceopen(const char *file)
if (strlen(file) < 1025)
{
std::strncpy(file_trace, file, 1024);
file_trace[1023] = '\0';
}
else
{
@ -4100,6 +4109,7 @@ void createdir(const char *path)
if (strlen(path) < 1025)
{
std::strncpy(buff, path, 1024);
buff[1023] = '\0';
}
else
{
@ -4145,6 +4155,7 @@ int repstr(char *str, const char *pat, const char *rep)
if (strlen(p) < 1025)
{
std::strncpy(r, p, 1024);
r[1023] = '\0';
}
else
{
@ -5083,6 +5094,7 @@ int rtk_uncompress(const char *file, char *uncfile)
if (strlen(file) < 1025)
{
std::strncpy(tmpfile, file, 1024);
tmpfile[1023] = '\0';
}
else
{
@ -5279,6 +5291,7 @@ int expath(const char *path, char *paths[], int nmax)
if (strlen(paths[i]) < 1025)
{
std::strncpy(tmp, paths[i], 1024);
tmp[1023] = '\0';
}
else
{

View File

@ -164,6 +164,7 @@ int rtkopenstat(const char *file, int level)
if (strlen(file) < 1025)
{
std::strncpy(file_stat, file, 1024);
file_stat[1023] = '\0';
}
else
{

View File

@ -996,6 +996,7 @@ int rtksvrstart(rtksvr_t *svr, int cycle, int buffsize, int *strs,
if (strlen(rcvopts[i]) < 256)
{
std::strncpy(svr->rtcm[i].opt, rcvopts[i], 256);
svr->rtcm[i].opt[255] = '\0';
}
/* connect dgps corrections */

View File

@ -118,6 +118,7 @@ serial_t *openserial(const char *path, int mode, char *msg)
else if (strlen(path) < 128)
{
std::strncpy(port, path, 128);
port[127] = '\0';
}
for (i = 0; i < 10; i++)
@ -423,6 +424,7 @@ file_t *openfile(const char *path, int mode, char *msg)
if (strlen(path) < MAXSTRPATH)
{
std::strncpy(file->path, path, MAXSTRPATH);
file->path[MAXSTRPATH - 1] = '\0';
}
if ((p = strstr(file->path, "::")))
{
@ -744,6 +746,7 @@ void decodetcppath(const char *path, char *addr, char *port, char *user,
if (strlen(path) < MAXSTRPATH)
{
std::strncpy(buff, path, MAXSTRPATH);
buff[MAXSTRPATH - 1] = '\0';
}
if (!(p = strrchr(buff, '@')))
@ -759,12 +762,14 @@ void decodetcppath(const char *path, char *addr, char *port, char *user,
if (str)
{
std::strncpy(str, q + 1, NTRIP_MAXSTR);
str[NTRIP_MAXSTR - 1] = '\0';
}
}
*p = '\0';
if (mntpnt)
{
std::strncpy(mntpnt, p + 1, 256);
mntpnt[255] = '\0';
}
}
if ((p = strrchr(buff, '@')))
@ -776,11 +781,13 @@ void decodetcppath(const char *path, char *addr, char *port, char *user,
if (passwd)
{
std::strncpy(passwd, q + 1, 256);
passwd[255] = '\0';
}
}
if (user)
{
std::strncpy(user, buff, 256);
user[255] = '\0';
}
}
else
@ -794,11 +801,13 @@ void decodetcppath(const char *path, char *addr, char *port, char *user,
if (port)
{
std::strncpy(port, q + 1, 256);
port[255] = '\0';
}
}
if (addr)
{
std::strncpy(addr, p, 1024);
std::strncpy(addr, p, 256);
addr[255] = '\0';
}
}
@ -1081,6 +1090,7 @@ void updatetcpsvr(tcpsvr_t *tcpsvr, char *msg)
continue;
}
std::strncpy(saddr, tcpsvr->cli[i].saddr, 256);
saddr[255] = '\0';
n++;
}
if (n == 0)
@ -1149,6 +1159,7 @@ int accsock(tcpsvr_t *tcpsvr, char *msg)
if (strlen(inet_ntoa(addr.sin_addr)) < 256)
{
std::strncpy(tcpsvr->cli[i].saddr, inet_ntoa(addr.sin_addr), 256);
tcpsvr->cli[i].saddr[255] = '\0';
}
sprintf(msg, "%s", tcpsvr->cli[i].saddr);
tracet(2, "accsock: connected sock=%d addr=%s\n", tcpsvr->cli[i].sock, tcpsvr->cli[i].saddr);
@ -1848,6 +1859,7 @@ void decodeftppath(const char *path, char *addr, char *file, char *user,
if (strlen(path) < MAXSTRPATH)
{
std::strncpy(buff, path, MAXSTRPATH);
buff[MAXSTRPATH - 1] = '\0';
}
if ((p = strchr(buff, '/')))
@ -2292,6 +2304,7 @@ int stropen(stream_t *stream, int type, int mode, const char *path)
if (strlen(path) < MAXSTRPATH)
{
std::strncpy(stream->path, path, MAXSTRPATH);
stream->path[MAXSTRPATH - 1] = '\0';
}
stream->inb = stream->inr = stream->outb = stream->outr = 0;
stream->tick = tickget();
@ -2721,6 +2734,7 @@ void strsetdir(const char *dir)
if (strlen(dir) < 1024)
{
std::strncpy(localdir, dir, 1024);
localdir[1023] = '\0';
}
}
@ -2736,6 +2750,7 @@ void strsetproxy(const char *addr)
if (strlen(addr) < 256)
{
std::strncpy(proxyaddr, addr, 256);
proxyaddr[255] = '\0';
}
}