summaryrefslogtreecommitdiff
path: root/strfunc.c
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2008-06-14 20:53:45 -0700
committerH. Peter Anvin <hpa@zytor.com>2008-06-14 20:53:45 -0700
commit2cb033e0d94a229810b110a49a5052ef1a4dc7db (patch)
treec47f829721f3ea0a8c2c794a622837132afe50b7 /strfunc.c
parent518df30308c555a8f8d7e359cb31688af0c686db (diff)
downloadnasm-2cb033e0d94a229810b110a49a5052ef1a4dc7db.tar.gz
strfunc: always null-terminate the output buffer
Make sure that the buffer is always null-terminated, even though we do have to use the length, since the string can (and often will) have embedded nulls.
Diffstat (limited to 'strfunc.c')
-rw-r--r--strfunc.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/strfunc.c b/strfunc.c
index 9fb72706..ac56ac73 100644
--- a/strfunc.c
+++ b/strfunc.c
@@ -158,10 +158,13 @@ size_t string_transform(char *str, size_t len, char **out, enum strfunc func)
transform_func transform = str_transforms[func];
size_t outlen;
uint8_t *s = (uint8_t *)str;
+ char *buf;
outlen = transform(s, len, NULL);
if (outlen == (size_t)-1)
return -1;
- return transform(s, len, *out = nasm_malloc(outlen));
+ *out = buf = nasm_malloc(outlen+1);
+ buf[outlen] = '\0'; /* Forcibly null-terminate the buffer */
+ return transform(s, len, buf);
}