diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2003-04-02 23:01:11 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2003-04-02 23:01:11 +0000 |
commit | a7dc4e8ecb1e6ee7b2092b5d330df7114e03da1d (patch) | |
tree | 962f60117c73961f7c517be32fbbd139848c27ec | |
parent | 8e063571fdde4e20da0cef6e3364783f48cbddee (diff) |
Use snprintf instead of sprintf; deraadt@ OK
-rw-r--r-- | lib/libkeynote/environment.c | 45 | ||||
-rw-r--r-- | lib/libkeynote/keynote.y | 6 |
2 files changed, 34 insertions, 17 deletions
diff --git a/lib/libkeynote/environment.c b/lib/libkeynote/environment.c index 39fd51d4a3f..8cd0edb4aeb 100644 --- a/lib/libkeynote/environment.c +++ b/lib/libkeynote/environment.c @@ -1,4 +1,4 @@ -/* $OpenBSD: environment.c,v 1.16 2001/09/03 20:14:51 deraadt Exp $ */ +/* $OpenBSD: environment.c,v 1.17 2003/04/02 23:01:10 millert Exp $ */ /* * The author of this code is Angelos D. Keromytis (angelos@dsl.cis.upenn.edu) * @@ -82,6 +82,7 @@ static char * keynote_get_action_authorizers(char *name) { struct keylist *kl; + size_t cachesize; int len; if (!strcmp(name, KEYNOTE_CALLBACK_CLEANUP) || @@ -99,16 +100,17 @@ keynote_get_action_authorizers(char *name) if (keynote_current_session->ks_authorizers_cache != (char *) NULL) return keynote_current_session->ks_authorizers_cache; - for (len = 0, kl = keynote_current_session->ks_action_authorizers; + for (cachesize = 0, kl = keynote_current_session->ks_action_authorizers; kl != (struct keylist *) NULL; kl = kl->key_next) if (kl->key_stringkey != (char *) NULL) - len += strlen(kl->key_stringkey) + 1; + cachesize += strlen(kl->key_stringkey) + 1; - if (len == 0) + if (cachesize == 0) return ""; - keynote_current_session->ks_authorizers_cache = (char *) calloc(len, sizeof(char)); + keynote_current_session->ks_authorizers_cache = + (char *) calloc(cachesize, sizeof(char)); if (keynote_current_session->ks_authorizers_cache == (char *) NULL) { keynote_errno = ERROR_MEMORY; @@ -120,8 +122,13 @@ keynote_get_action_authorizers(char *name) kl = kl->key_next) if (kl->key_stringkey != (char *) NULL) { - sprintf(keynote_current_session->ks_authorizers_cache + len, "%s,", - kl->key_stringkey); +#if !defined(HAVE_SNPRINTF) + sprintf(keynote_current_session->ks_authorizers_cache + len, + "%s,", kl->key_stringkey); +#else /* !HAVE_SNPRINTF */ + snprintf(keynote_current_session->ks_authorizers_cache + len, + cachesize - len, "%s,", kl->key_stringkey); +#endif /* !HAVE_SNPRINTF */ len += strlen(kl->key_stringkey) + 1; } @@ -136,6 +143,7 @@ static char * keynote_get_values(char *name) { int i, len; + size_t cachesize; if (!strcmp(name, KEYNOTE_CALLBACK_CLEANUP) || !strcmp(name, KEYNOTE_CALLBACK_INITIALIZE)) @@ -152,24 +160,29 @@ keynote_get_values(char *name) if (keynote_current_session->ks_values_cache != (char *) NULL) return keynote_current_session->ks_values_cache; - for (len = 0, i = 0; i < keynote_current_session->ks_values_num; i++) - len += strlen(keynote_current_session->ks_values[i]) + 1; + for (cachesize = 0, i = 0; i < keynote_current_session->ks_values_num; i++) + cachesize += strlen(keynote_current_session->ks_values[i]) + 1; + + if (cachesize == 0) + return ""; - keynote_current_session->ks_values_cache = (char *) calloc(len, - sizeof(char)); + keynote_current_session->ks_values_cache = + (char *) calloc(cachesize, sizeof(char)); if (keynote_current_session->ks_values_cache == (char *) NULL) { keynote_errno = ERROR_MEMORY; return (char *) NULL; } - if (len == 0) - return ""; - for (len = 0, i = 0; i < keynote_current_session->ks_values_num; i++) { - sprintf(keynote_current_session->ks_values_cache + len, "%s,", - keynote_current_session->ks_values[i]); +#if !defined(HAVE_SNPRINTF) + sprintf(keynote_current_session->ks_values_cache + len, + "%s,", keynote_current_session->ks_values[i]); +#else /* !HAVE_SNPRINTF */ + snprintf(keynote_current_session->ks_values_cache + len, + cachesize - len, "%s,", keynote_current_session->ks_values[i]); +#endif /* !HAVE_SNPRINTF */ len += strlen(keynote_current_session->ks_values[i]) + 1; } diff --git a/lib/libkeynote/keynote.y b/lib/libkeynote/keynote.y index 53ce91ae3cd..7a2820deef7 100644 --- a/lib/libkeynote/keynote.y +++ b/lib/libkeynote/keynote.y @@ -1,4 +1,4 @@ -/* $OpenBSD: keynote.y,v 1.12 2002/05/27 06:29:14 deraadt Exp $ */ +/* $OpenBSD: keynote.y,v 1.13 2003/04/02 23:01:10 millert Exp $ */ /* * The author of this code is Angelos D. Keromytis (angelos@dsl.cis.upenn.edu) * @@ -598,7 +598,11 @@ str: str DOTT str { if (keynote_exceptionflag || keynote_donteval) return -1; } +#if !defined(HAVE_SNPRINTF) + sprintf($$, "%s%s", $1, $3); +#else /* !HAVE_SNPRINTF */ snprintf($$, len, "%s%s", $1, $3); +#endif /* !HAVE_SNPRINTF */ free($1); free($3); if (keynote_lex_add($$, LEXTYPE_CHAR) == -1) |