diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2004-07-04 15:44:13 +0000 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2004-07-04 15:44:13 +0000 |
commit | bfcc6ade94b279fd03a5efcbf24fe1e151584073 (patch) | |
tree | 065d9d71eb4a5c7d2ef7c502eec2b921efbdca35 /hcid/lib.c | |
parent | 50111729540851e01dd1471d4ce742ee44f437e7 (diff) |
Add size parameter to expand_name()
Diffstat (limited to 'hcid/lib.c')
-rw-r--r-- | hcid/lib.c | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -53,7 +53,7 @@ volatile sig_atomic_t __io_canceled; * Device name expansion * %d - device id */ -char *expand_name(char *dst, char *str, int dev_id) +char *expand_name(char *dst, int size, char *str, int dev_id) { register int sp, np, olen; char *opt, buf[10]; @@ -62,7 +62,7 @@ char *expand_name(char *dst, char *str, int dev_id) return NULL; sp = np = 0; - while (str[sp]) { + while (np < size - 1 && str[sp]) { switch (str[sp]) { case '%': opt = NULL; @@ -88,7 +88,8 @@ char *expand_name(char *dst, char *str, int dev_id) if (opt) { /* substitute */ olen = strlen(opt); - memcpy(dst + np, opt, olen); + if (np + olen < size - 1) + memcpy(dst + np, opt, olen); np += olen; } sp += 2; |