diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/authz.h | 13 | ||||
| -rw-r--r-- | src/util.c | 60 |
2 files changed, 0 insertions, 73 deletions
diff --git a/src/authz.h b/src/authz.h index ad39b35..f9fbfa3 100644 --- a/src/authz.h +++ b/src/authz.h @@ -138,14 +138,6 @@ int cmd_validate(const policy_t *p, validate_opts o); // util.c -------------------------------------------------------------------- -// A growing string. strncat with hand-computed room is how buffer bugs are -// born. -typedef struct { - char *s; // never NULL once sb_init has run - size_t len; - size_t cap; -} strbuf_t; - // A file, one entry per line. The newline is kept, and a last line without one // is given one, so the lines may be written straight back out again. typedef struct { @@ -164,11 +156,6 @@ void lines_free(lines_t *l); // nothing at all for a file that is optional here. int authz_read_lines(const char *path, lines_t *l); -void sb_init(strbuf_t *b); -void sb_add(strbuf_t *b, const char *s); -void sb_addf(strbuf_t *b, const char *fmt, ...); -void sb_free(strbuf_t *b); - void *xmalloc(size_t n); void *xrealloc(void *p, size_t n); char *xstrdup(const char *s); @@ -3,7 +3,6 @@ // somewhere a caller forgot to look. #include "authz.h" -#include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -17,65 +16,6 @@ static void oom(void) exit(3); } -void sb_init(strbuf_t *b) -{ - b->cap = 64; - b->len = 0; - b->s = xmalloc(b->cap); - b->s[0] = '\0'; -} - -static void sb_room(strbuf_t *b, size_t extra) -{ - if (b->len + extra + 1 <= b->cap) - return; - while (b->len + extra + 1 > b->cap) - b->cap *= 2; - b->s = xrealloc(b->s, b->cap); -} - -void sb_add(strbuf_t *b, const char *s) -{ - size_t n; - - if (s == NULL) - return; - n = strlen(s); - sb_room(b, n); - memcpy(b->s + b->len, s, n + 1); - b->len += n; -} - -void sb_addf(strbuf_t *b, const char *fmt, ...) -{ - va_list ap; - int n; - char *out; - - va_start(ap, fmt); - n = vsnprintf(NULL, 0, fmt, ap); - va_end(ap); - if (n < 0) - return; - sb_room(b, (size_t)n); - va_start(ap, fmt); - out = b->s + b->len; - n = vsnprintf(out, b->cap - b->len, fmt, ap); - va_end(ap); - if (n < 0) { - b->s[b->len] = '\0'; - return; - } - b->len += (size_t)n; -} - -void sb_free(strbuf_t *b) -{ - free(b->s); - b->s = NULL; - b->len = b->cap = 0; -} - void *xmalloc(size_t n) { void *p = malloc(n != 0 ? n : 1); |
