diff options
author | Jerry Jelinek <jerry.jelinek@joyent.com> | 2014-12-23 23:19:21 +0000 |
---|---|---|
committer | Jerry Jelinek <jerry.jelinek@joyent.com> | 2014-12-23 23:19:21 +0000 |
commit | af9034a8036f884fc06874c445d85ac9f416f4fe (patch) | |
tree | 01ceaeec83dcf7e2bab07cbf2db7f40b7fcb5622 /usr/src/lib/libcmdutils/common | |
parent | 8af96fbb6bb47d4566bcfef02a8e551164eb2208 (diff) | |
parent | 5422785d352a2bb398daceab3d1898a8aa64d006 (diff) | |
download | illumos-joyent-release-20141225.tar.gz |
[illumos-gate merge]20141225release-20141225
commit 5422785d352a2bb398daceab3d1898a8aa64d006
5481 CVE-2012-1750 mailx(1) tilde expansion vulnerability
5482 CVE-2014-7844, CVE-2004-2771 - more mailx(1) woes
commit 196c7f05d2deba7404e90ad67f3861185c78ca2d
5480 CVE-2012-3165 mailx(1) buffer overflow vulnerability
Diffstat (limited to 'usr/src/lib/libcmdutils/common')
-rw-r--r-- | usr/src/lib/libcmdutils/common/custr.c | 135 | ||||
-rw-r--r-- | usr/src/lib/libcmdutils/common/mapfile-vers | 7 |
2 files changed, 142 insertions, 0 deletions
diff --git a/usr/src/lib/libcmdutils/common/custr.c b/usr/src/lib/libcmdutils/common/custr.c new file mode 100644 index 0000000000..1ec72de9dd --- /dev/null +++ b/usr/src/lib/libcmdutils/common/custr.c @@ -0,0 +1,135 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * String utility functions with dynamic memory management. + */ + +/* + * Copyright 2014, Joyent, Inc. + */ + +#include <stdlib.h> +#include <err.h> +#include <string.h> + +#include "libcmdutils.h" + +struct custr { + size_t cus_strlen; + size_t cus_datalen; + char *cus_data; +}; + +#define STRING_CHUNK_SIZE 64 + +void +custr_reset(custr_t *cus) +{ + if (cus->cus_data == NULL) + return; + + cus->cus_strlen = 0; + cus->cus_data[0] = '\0'; +} + +size_t +custr_len(custr_t *cus) +{ + return (cus->cus_strlen); +} + +const char * +custr_cstr(custr_t *cus) +{ + return (cus->cus_data); +} + +int +custr_appendc(custr_t *cus, char newc) +{ + char news[2]; + + news[0] = newc; + news[1] = '\0'; + + return (custr_append(cus, news)); +} + +int +custr_append(custr_t *cus, const char *news) +{ + size_t len = strlen(news); + size_t chunksz = STRING_CHUNK_SIZE; + + while (chunksz < len) { + chunksz *= 2; + } + + if (len + cus->cus_strlen + 1 >= cus->cus_datalen) { + char *new_data; + size_t new_datalen = cus->cus_datalen + chunksz; + + /* + * Allocate replacement memory: + */ + if ((new_data = malloc(new_datalen)) == NULL) { + return (-1); + } + + /* + * Copy existing data into replacement memory and free + * the old memory. + */ + if (cus->cus_data != NULL) { + (void) memcpy(new_data, cus->cus_data, + cus->cus_strlen + 1); + free(cus->cus_data); + } + + /* + * Swap in the replacement buffer: + */ + cus->cus_data = new_data; + cus->cus_datalen = new_datalen; + } + /* + * Append new string to existing string: + */ + (void) memcpy(cus->cus_data + cus->cus_strlen, news, len + 1); + cus->cus_strlen += len; + + return (0); +} + +int +custr_alloc(custr_t **cus) +{ + custr_t *t; + + if ((t = calloc(1, sizeof (*t))) == NULL) { + *cus = NULL; + return (-1); + } + + *cus = t; + return (0); +} + +void +custr_free(custr_t *cus) +{ + if (cus == NULL) + return; + + free(cus->cus_data); + free(cus); +} diff --git a/usr/src/lib/libcmdutils/common/mapfile-vers b/usr/src/lib/libcmdutils/common/mapfile-vers index e4c5940c31..640959e4b5 100644 --- a/usr/src/lib/libcmdutils/common/mapfile-vers +++ b/usr/src/lib/libcmdutils/common/mapfile-vers @@ -42,6 +42,13 @@ $mapfile_version 2 SYMBOL_VERSION SUNWprivate_1.1 { global: add_tnode; + custr_alloc; + custr_append; + custr_appendc; + custr_cstr; + custr_free; + custr_len; + custr_reset; destroy_tree; findnextgid; findnextuid; |