diff options
author | Bjorn Sandell <biorn@cvs.openbsd.org> | 2006-03-31 09:23:40 +0000 |
---|---|---|
committer | Bjorn Sandell <biorn@cvs.openbsd.org> | 2006-03-31 09:23:40 +0000 |
commit | 7e3735592a3c24a7b0114341063c515db99aa2c1 (patch) | |
tree | bab7bef485e455a79f5557665972665ca5939d6a /kerberosV | |
parent | 92ba52e17920dbd78f8b9df720d702ce48265ce4 (diff) |
Check malloc return value
From Alexey Dobriyan
Diffstat (limited to 'kerberosV')
-rw-r--r-- | kerberosV/src/kadmin/load.c | 65 |
1 files changed, 38 insertions, 27 deletions
diff --git a/kerberosV/src/kadmin/load.c b/kerberosV/src/kadmin/load.c index ea8b81e7dd0..92ace9afaeb 100644 --- a/kerberosV/src/kadmin/load.c +++ b/kerberosV/src/kadmin/load.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997-2000 Kungliga Tekniska Högskolan + * Copyright (c) 1997-2002 Kungliga Tekniska Högskolan * (Royal Institute of Technology, Stockholm, Sweden). * All rights reserved. * @@ -34,7 +34,7 @@ #include "kadmin_locl.h" #include <kadm5/private.h> -RCSID("$KTH: load.c,v 1.40 2001/01/04 15:59:26 assar Exp $"); +RCSID("$KTH: load.c,v 1.44 2002/09/04 20:44:35 joda Exp $"); struct entry { char *principal; @@ -47,7 +47,7 @@ struct entry { char *valid_end; char *pw_end; char *flags; - char *etypes; + char *generation; }; static char * @@ -172,6 +172,8 @@ parse_keys(hdb_entry *ent, char *str) memset(key, 0, sizeof(*key)); if(sscanf(p, "%d", &tmp) == 1) { key->mkvno = malloc(sizeof(*key->mkvno)); + if (key->mkvno == NULL) + krb5_errx (context, 1, "malloc: out of memory"); *key->mkvno = tmp; } else key->mkvno = NULL; @@ -282,24 +284,34 @@ parse_hdbflags2int(HDBFlags *f, const char *s) return ret; } -#if 0 -static void -parse_etypes(char *str, unsigned **val, unsigned *len) +static int +parse_generation(char *str, GENERATION **gen) { - unsigned v; - - *val = NULL; - *len = 0; - while(sscanf(str, "%u", &v) == 1) { - *val = realloc(*val, (*len+1) * sizeof(**val)); - (*val)[(*len)++] = v; - str = strchr(str, ':'); - if(str == NULL) - break; - str++; + char *p; + int v; + + if(strcmp(str, "-") == 0 || *str == '\0') { + *gen = NULL; + return 0; } + *gen = calloc(1, sizeof(**gen)); + if (*gen == NULL) + krb5_errx (context, 1, "calloc: out of memory"); + + p = strsep(&str, ":"); + if(parse_time_string(&(*gen)->time, p) != 1) + return -1; + p = strsep(&str, ":"); + if(sscanf(p, "%d", &v) != 1) + return -1; + (*gen)->usec = v; + p = strsep(&str, ":"); + if(sscanf(p, "%d", &v) != 1) + return -1; + (*gen)->gen = v - 1; /* XXX gets bumped in _hdb_store */ + return 0; } -#endif + /* * Parse the dump file in `filename' and create the database (merging @@ -311,7 +323,7 @@ doit(const char *filename, int merge) { krb5_error_code ret; FILE *f; - char s[1024]; + char s[8192]; /* XXX should fix this properly */ char *p; int line; int flags = O_RDWR; @@ -382,7 +394,7 @@ doit(const char *filename, int merge) e.flags = p; p = skip_next(p); - e.etypes = p; + e.generation = p; p = skip_next(p); memset(&ent, 0, sizeof(ent)); @@ -454,14 +466,13 @@ doit(const char *filename, int merge) hdb_free_entry (context, &ent); continue; } -#if 0 - ALLOC(ent.etypes); - parse_etypes(e.etypes, &ent.etypes->val, &ent.etypes->len); - if(ent.etypes->len == 0) { - free(ent.etypes); - ent.etypes = NULL; + + if(parse_generation(e.generation, &ent.generation) == -1) { + fprintf (stderr, "%s:%d:error parsing generation (%s)\n", + filename, line, e.generation); + hdb_free_entry (context, &ent); + continue; } -#endif ret = db->store(context, db, HDB_F_REPLACE, &ent); hdb_free_entry (context, &ent); |