replaced strlen with strnlen

This commit is contained in:
Fufu Fang 2021-08-31 12:31:02 +01:00
parent a9988c794a
commit af45bcfa19
No known key found for this signature in database
GPG Key ID: 0F6BB5EF6F8BB729
3 changed files with 4 additions and 2 deletions

View File

@ -37,6 +37,7 @@ static LinkTable *single_LinkTable_new(const char *url)
char *ptr = strrchr(url, '/');
int dir_len = ptr - url;
char *dir_name = CALLOC(dir_len + 1, sizeof(char));
free(dir_name);
return NULL;
}

View File

@ -295,7 +295,8 @@ XML_parser_general(void *data, const char *elem, const char **attr)
}
}
if (!linkname_set && strlen(title) > 0 && strlen(suffix) > 0) {
if (!linkname_set && strnlen(title, MAX_PATH_LEN) > 0 &&
strnlen(suffix, MAX_PATH_LEN) > 0) {
snprintf(link->linkname, MAX_FILENAME_LEN, "%02d - %s.%s",
track, title, suffix);
linkname_set = 1;

View File

@ -150,7 +150,7 @@ void FREE(void *ptr)
char *str_to_hex(char *s)
{
char *hex = CALLOC(strlen(s) * 2 + 1, sizeof(char));
char *hex = CALLOC(strnlen(s, MAX_PATH_LEN) * 2 + 1, sizeof(char));
for (char *c = s, *h = hex; *c; c++, h += 2) {
sprintf(h, "%x", *c);
}