diff options
| author | Ken Raeburn <raeburn@mit.edu> | 2007-07-12 23:33:25 +0000 |
|---|---|---|
| committer | Ken Raeburn <raeburn@mit.edu> | 2007-07-12 23:33:25 +0000 |
| commit | 52571d9201c7bef4dc5ebdf14a41db1f7baddc8e (patch) | |
| tree | 9f108e05e8881ea19954b4959fdca96d47daa615 /src/util/support | |
| parent | 57913ccc175061dd41e98914d50eda56dd9685c0 (diff) | |
| download | krb5-52571d9201c7bef4dc5ebdf14a41db1f7baddc8e.tar.gz krb5-52571d9201c7bef4dc5ebdf14a41db1f7baddc8e.tar.xz krb5-52571d9201c7bef4dc5ebdf14a41db1f7baddc8e.zip | |
Avoid use of unchecked sprintf in libraries. Use asprintf if the
output buffer is allocated according to the size of data to be
written, or snprintf otherwise.
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@19703 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/util/support')
| -rw-r--r-- | src/util/support/errors.c | 3 | ||||
| -rw-r--r-- | src/util/support/plugins.c | 31 |
2 files changed, 14 insertions, 20 deletions
diff --git a/src/util/support/errors.c b/src/util/support/errors.c index e2101a2a9..94290f857 100644 --- a/src/util/support/errors.c +++ b/src/util/support/errors.c @@ -125,7 +125,8 @@ krb5int_get_error (struct errinfo *ep, long code) return r2; } format_number: - sprintf (ep->scratch_buf, _("error %ld"), code); + snprintf (ep->scratch_buf, sizeof(ep->scratch_buf), + _("error %ld"), code); return ep->scratch_buf; } r = (char *) fptr(code); diff --git a/src/util/support/plugins.c b/src/util/support/plugins.c index b26726fab..99d3aea57 100644 --- a/src/util/support/plugins.c +++ b/src/util/support/plugins.c @@ -49,6 +49,8 @@ #include <unistd.h> #endif +#include "k5-platform.h" + #include <stdarg.h> static void Tprintf (const char *fmt, ...) { @@ -377,15 +379,11 @@ krb5int_get_plugin_filenames (const char * const *filebases, char ***filenames) if (!err) { int j; for (i = 0; !err && (filebases[i] != NULL); i++) { - size_t baselen = strlen (filebases[i]); for (j = 0; !err && (fileexts[j] != NULL); j++) { - size_t len = baselen + strlen (fileexts[j]) + 2; /* '.' + NULL */ - tempnames[i+j] = malloc (len * sizeof (char)); - if (tempnames[i+j] == NULL) { - err = errno; - } else { - sprintf (tempnames[i+j], "%s%s", filebases[i], fileexts[j]); - } + if (asprintf(&tempnames[i+j], "%s%s", filebases[i], fileexts[j]) < 0) { + tempnames[i+j] = NULL; + err = errno; + } } } } @@ -426,7 +424,6 @@ krb5int_open_plugin_dirs (const char * const *dirnames, } for (i = 0; !err && dirnames[i] != NULL; i++) { - size_t dirnamelen = strlen (dirnames[i]) + 1; /* '/' */ if (filenames != NULL) { /* load plugins with names from filenames from each directory */ int j; @@ -436,11 +433,9 @@ krb5int_open_plugin_dirs (const char * const *dirnames, char *filepath = NULL; if (!err) { - filepath = malloc (dirnamelen + strlen (filenames[j]) + 1); /* NULL */ - if (filepath == NULL) { - err = errno; - } else { - sprintf (filepath, "%s/%s", dirnames[i], filenames[j]); + if (asprintf(&filepath, "%s/%s", dirnames[i], filenames[j]) < 0) { + filepath = NULL; + err = errno; } } @@ -472,11 +467,9 @@ krb5int_open_plugin_dirs (const char * const *dirnames, if (!err) { int len = NAMELEN (d); - filepath = malloc (dirnamelen + len + 1); /* NULL */ - if (filepath == NULL) { - err = errno; - } else { - sprintf (filepath, "%s/%*s", dirnames[i], len, d->d_name); + if (asprintf(&filepath, "%s/%*s", dirnames[i], len, d->d_name) < 0) { + filepath = NULL; + err = errno; } } |
