pam_cgfs: strncat => strlcat

parent f1e05b90
...@@ -63,6 +63,10 @@ ...@@ -63,6 +63,10 @@
#include "include/strlcpy.h" #include "include/strlcpy.h"
#endif #endif
#ifndef HAVE_STRLCAT
#include "include/strlcat.h"
#endif
#define pam_cgfs_debug_stream(stream, format, ...) \ #define pam_cgfs_debug_stream(stream, format, ...) \
do { \ do { \
fprintf(stream, "%s: %d: %s: " format, __FILE__, __LINE__, \ fprintf(stream, "%s: %d: %s: " format, __FILE__, __LINE__, \
...@@ -1617,6 +1621,7 @@ static char *string_join(const char *sep, const char **parts, bool use_as_prefix ...@@ -1617,6 +1621,7 @@ static char *string_join(const char *sep, const char **parts, bool use_as_prefix
char **p; char **p;
size_t sep_len = strlen(sep); size_t sep_len = strlen(sep);
size_t result_len = use_as_prefix * sep_len; size_t result_len = use_as_prefix * sep_len;
size_t buf_len;
if (!parts) if (!parts)
return NULL; return NULL;
...@@ -1625,17 +1630,18 @@ static char *string_join(const char *sep, const char **parts, bool use_as_prefix ...@@ -1625,17 +1630,18 @@ static char *string_join(const char *sep, const char **parts, bool use_as_prefix
for (p = (char **)parts; *p; p++) for (p = (char **)parts; *p; p++)
result_len += (p > (char **)parts) * sep_len + strlen(*p); result_len += (p > (char **)parts) * sep_len + strlen(*p);
result = calloc(result_len + 1, sizeof(char)); buf_len = result_len + 1;
result = calloc(buf_len, sizeof(char));
if (!result) if (!result)
return NULL; return NULL;
if (use_as_prefix) if (use_as_prefix)
(void)strlcpy(result, sep, (result_len + 1) * sizeof(char)); (void)strlcpy(result, sep, buf_len * sizeof(char));
for (p = (char **)parts; *p; p++) { for (p = (char **)parts; *p; p++) {
if (p > (char **)parts) if (p > (char **)parts)
strncat(result, sep, sep_len); (void)strlcat(result, sep, buf_len * sizeof(char));
strncat(result, *p, strlen(*p)); (void)strlcat(result, *p, buf_len * sizeof(char));
} }
return result; return result;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment