kvm: Use strlcat helper for copying cmdline params

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
Cyrill Gorcunov
2010-05-10 14:18:17 +04:00
committed by Will Deacon
parent 0f9983b2bd
commit 0b322d9635
3 changed files with 28 additions and 1 deletions
+2
View File
@@ -44,4 +44,6 @@ do { \
__stringify(cnd) "\n"); \
} while (0)
extern size_t strlcat(char *dest, const char *src, size_t count);
#endif /* KVM__UTIL_H */
+1 -1
View File
@@ -69,7 +69,7 @@ int main(int argc, char *argv[])
strcpy(real_cmdline, "notsc nolapic nosmp noacpi earlyprintk=serial,keep");
if (kernel_cmdline) {
strncat(real_cmdline, kernel_cmdline, sizeof(real_cmdline));
strlcat(real_cmdline, kernel_cmdline, sizeof(real_cmdline));
real_cmdline[sizeof(real_cmdline)-1] = '\0';
}
+25
View File
@@ -74,3 +74,28 @@ void die_perror(const char *s)
perror(s);
exit(1);
}
/**
* strlcat - Append a length-limited, %NUL-terminated string to another
* @dest: The string to be appended to
* @src: The string to append to it
* @count: The size of the destination buffer.
*/
size_t strlcat(char *dest, const char *src, size_t count)
{
size_t dsize = strlen(dest);
size_t len = strlen(src);
size_t res = dsize + len;
DIE_IF(dsize >= count);
dest += dsize;
count -= dsize;
if (len >= count)
len = count - 1;
memcpy(dest, src, len);
dest[len] = 0;
return res;
}