mirror of
https://github.com/clearlinux/kvmtool.git
synced 2026-06-16 02:15:47 +00:00
kvm: Use strlcat helper for copying cmdline params
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
committed by
Will Deacon
parent
0f9983b2bd
commit
0b322d9635
@@ -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 */
|
||||
|
||||
@@ -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';
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user