Replace all strcat with strlcat

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2023-03-05 21:46:37 +08:00 committed by Petro Karashchenko
parent f60d23fdb9
commit 134b8b538f
12 changed files with 46 additions and 55 deletions

View File

@ -4036,7 +4036,7 @@ static FAR char *mystrconcat(FAR const char *str, FAR const char *cat)
if (answer)
{
strlcpy(answer, str, len);
strcat(answer, cat);
strlcat(answer, cat, len);
}
return answer;

View File

@ -165,8 +165,8 @@ int main(int argc, FAR char **argv)
cmd[0] = '\0';
for (i = optind; i < argc; i++)
{
strcat(cmd, argv[i]);
strcat(cmd, " ");
strlcat(cmd, argv[i], sizeof(cmd));
strlcat(cmd, " ", sizeof(cmd));
}
arg.command = cmd;

View File

@ -236,7 +236,8 @@ int main(int argc, char *argv[])
{
/* Got it; put together the full name. */
strcat(g_url, script_name + (star - g_file));
strlcat(g_url, script_name + (star - g_file),
sizeof(g_url));
/* XXX Whack the script_name, too? */

View File

@ -924,10 +924,10 @@ static int httpd_tilde_map1(httpd_conn *hc)
if (prefix[0] != '\0')
{
strcat(hc->expnfilename, "/");
strlcat(hc->expnfilename, "/", hc->maxexpnfilename + 1);
}
strcat(hc->expnfilename, temp);
strlcat(hc->expnfilename, temp, hc->maxexpnfilename + 1);
return 1;
}
#endif /* CONFIG_THTTPD_TILDE_MAP1 */
@ -975,8 +975,8 @@ static int httpd_tilde_map2(httpd_conn *hc)
strlcpy(hc->altdir, pw->pw_dir, hc->maxaltdir + 1);
if (postfix[0] != '\0')
{
strcat(hc->altdir, "/");
strcat(hc->altdir, postfix);
strlcat(hc->altdir, "/", hc->maxaltdir + 1);
strlcat(hc->altdir, postfix, hc->maxaltdir + 1);
}
alt = expand_filename(hc->altdir, &rest, true);
@ -1116,8 +1116,8 @@ static int vhost_map(httpd_conn *hc)
httpd_realloc_str(&hc->expnfilename, &hc->maxexpnfilename,
strlen(hc->hostdir) + 1 + len);
strlcpy(hc->expnfilename, hc->hostdir, hc->maxexpnfilename + 1);
strcat(hc->expnfilename, "/");
strcat(hc->expnfilename, tempfilename);
strlcat(hc->expnfilename, "/", hc->maxexpnfilename + 1);
strlcat(hc->expnfilename, tempfilename, hc->maxexpnfilename + 1);
return 1;
}
#endif
@ -2875,14 +2875,14 @@ int httpd_parse_request(httpd_conn *hc)
httpd_realloc_str(&hc->accept, &hc->maxaccept,
strlen(hc->accept) + 2 + strlen(cp));
strcat(hc->accept, ", ");
strlcat(hc->accept, ", ", hc->maxaccepte + 1);
}
else
{
httpd_realloc_str(&hc->accept, &hc->maxaccept, strlen(cp));
}
strcat(hc->accept, cp);
strlcat(hc->accept, cp, hc->maxaccepte + 1);
}
else if (strncasecmp(buf, "Accept-Encoding:", 16) == 0)
{
@ -2899,7 +2899,7 @@ int httpd_parse_request(httpd_conn *hc)
httpd_realloc_str(&hc->accepte, &hc->maxaccepte,
strlen(hc->accepte) + 2 + strlen(cp));
strcat(hc->accepte, ", ");
strlcat(hc->accepte, ", ", hc->maxaccepte + 1);
}
else
{
@ -3296,7 +3296,7 @@ int httpd_start_request(httpd_conn *hc, struct timeval *nowp)
indxlen = strlen(indexname);
if (indxlen == 0 || indexname[indxlen - 1] != '/')
{
strcat(indexname, "/");
strlcat(indexname, "/", maxindexname + 1);
}
if (strcmp(indexname, "./") == 0)
@ -3304,7 +3304,7 @@ int httpd_start_request(httpd_conn *hc, struct timeval *nowp)
indexname[0] = '\0';
}
strcat(indexname, index_names[i]);
strlcat(indexname, index_names[i], maxindexname + 1);
if (stat(indexname, &hc->sb) >= 0)
{
goto got_one;

View File

@ -164,7 +164,6 @@ int xmlrpc_getstring(struct xmlrpc_s *xmlcall, char *arg)
int xmlrpc_buildresponse(struct xmlrpc_s *xmlcall, char *args, ...)
{
va_list argp;
int ret = 0;
int index = 0;
int close = 0;
int isstruct = 0;
@ -187,12 +186,13 @@ int xmlrpc_buildresponse(struct xmlrpc_s *xmlcall, char *args, ...)
if (xmlcall->error)
{
strcat(&xmlcall->response[strlen(xmlcall->response)], " <fault>\n");
strlcat(xmlcall->response, " <fault>\n",
sizeof(xmlcall->response));
}
else
{
strcat(&xmlcall->response[strlen(xmlcall->response)],
" <params><param>\n");
strlcat(xmlcall->response, " <params><param>\n",
sizeof(xmlcall->response));
}
va_start(argp, args);
@ -268,26 +268,18 @@ int xmlrpc_buildresponse(struct xmlrpc_s *xmlcall, char *args, ...)
if (xmlcall->error)
{
strcat(&xmlcall->response[strlen(xmlcall->response)],
" </fault>\r\n");
strlcat(xmlcall->response, " </fault>\r\n",
sizeof(xmlcall->response));
}
else
{
strcat(&xmlcall->response[strlen(xmlcall->response)],
" </param></params>\r\n");
strlcat(xmlcall->response, " </param></params>\r\n",
sizeof(xmlcall->response));
}
if (ret == 0)
{
strcat(&xmlcall->response[strlen(xmlcall->response)],
"</methodResponse>\r\n");
strlcat(xmlcall->response, "</methodResponse>\r\n",
sizeof(xmlcall->response));
xmlrpc_insertlength(xmlcall);
}
else
{
xmlcall->response[0] = 0;
}
return ret;
xmlrpc_insertlength(xmlcall);
return 0;
}

View File

@ -1106,7 +1106,7 @@ static FAR char *nsh_strcat(FAR struct nsh_vtbl_s *vtbl, FAR char *s1,
else
{
argument[s1size] = '\0'; /* (In case s1 was NULL) */
strcat(argument, s2);
strlcat(argument, s2, allocsize);
}
return argument;

View File

@ -333,14 +333,14 @@ static int compose_name(FAR const char *fname, FAR char *oname, int namelen)
return -1;
}
strncpy(oname, fname, namelen);
strlcpy(oname, fname, namelen);
p = strchr(oname, '.');
if (p != NULL)
{
*p = '_'; /* _ for dot */
}
strcat (oname, ".lzf");
strlcat(oname, ".lzf", namelen);
}
else
{
@ -372,13 +372,12 @@ static int compose_name(FAR const char *fname, FAR char *oname, int namelen)
static int run_file(FAR const char *fname)
{
struct stat mystat;
char oname[PATH_MAX + 1];
char oname[PATH_MAX];
int fd;
int fd2;
int ret;
memset(oname, 0, sizeof(oname));
if (compose_name(fname, oname, PATH_MAX + 1))
if (compose_name(fname, oname, sizeof(oname)))
{
return -1;
}

View File

@ -88,8 +88,7 @@ int main(int argc, FAR char *argv[])
int rc;
int i;
memset(command, 0, sizeof(command));
command[0] = '\0';
CPU_ZERO(&cpuset);
/* Parse command line options */
@ -156,8 +155,8 @@ int main(int argc, FAR char *argv[])
for (i = 0; i < argc - 2; i++)
{
strcat(command, argv[i + 2]);
strcat(command, " ");
strlcat(command, argv[i + 2], sizeof(command));
strlcat(command, " ", sizeof(command));
}
sched_setaffinity(gettid(), sizeof(cpu_set_t), &cpuset);

View File

@ -1091,23 +1091,23 @@ static int tcurses_vt100_setattributes(FAR struct termcurses_s *dev,
if (attrib & TCURS_ATTRIB_BLINK)
{
strcat(str, g_setblink);
strlcat(str, g_setblink, sizeof(str));
}
else
{
strcat(str, g_setnoblink);
strlcat(str, g_setnoblink, sizeof(str));
}
if (attrib & TCURS_ATTRIB_UNDERLINE)
{
strcat(str, g_setunderline);
strlcat(str, g_setunderline, sizeof(str));
}
else
{
strcat(str, g_setnounderline);
strlcat(str, g_setnounderline, sizeof(str));
}
strcat(str, "m");
strlcat(str, "m", sizeof(str));
ret = write(fd, str, strlen(str));

View File

@ -261,11 +261,11 @@ static int trace_cmd_cmd(int index, int argc, FAR char **argv, int notectlfd)
return ERROR;
}
memset(command, 0, sizeof(command));
command[0] = '\0';
while (index < argc)
{
strcat(command, argv[index]);
strcat(command, " ");
strlcat(command, argv[index], sizeof(command));
strlcat(command, " ", sizeof(command));
index++;
}

View File

@ -108,7 +108,7 @@ int main(int argc, FAR char *argv[])
printf("\n");
strcat(path, FILE_NAME);
strlcat(path, FILE_NAME, sizeof(path));
printf("open(%s)\n", path);
fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0777);

View File

@ -1021,7 +1021,7 @@ int main(int argc, FAR char *argv[])
if (ctx->mountdir[strlen(ctx->mountdir)-1] != '/')
{
strcat(ctx->mountdir, "/");
strlcat(ctx->mountdir, "/", sizeof(ctx->mountdir));
}
ctx->fileimage = calloc(ctx->max_file, 1);