diff options
author | hunt <hunt> | 2006-12-11 22:15:56 +0000 |
---|---|---|
committer | hunt <hunt> | 2006-12-11 22:15:56 +0000 |
commit | 8c3051485ff29d04f43e4c739ecee9b5f7ed9a31 (patch) | |
tree | 8cdb4a5e4385a1fc50d1a04e60e7e260980048bc | |
parent | 79e6d33f2b493b481da889dd64485c220a653c8c (diff) | |
download | systemtap-steved-8c3051485ff29d04f43e4c739ecee9b5f7ed9a31.tar.gz systemtap-steved-8c3051485ff29d04f43e4c739ecee9b5f7ed9a31.tar.xz systemtap-steved-8c3051485ff29d04f43e4c739ecee9b5f7ed9a31.zip |
2006-12-11 Martin Hunt <hunt@redhat.com>
* symbols.c (get_sections): Set buffer sizes to large enough
sizes to hold all possible values, but also include checks in case
we are wrong.
-rw-r--r-- | runtime/stpd/ChangeLog | 6 | ||||
-rw-r--r-- | runtime/stpd/symbols.c | 26 |
2 files changed, 27 insertions, 5 deletions
diff --git a/runtime/stpd/ChangeLog b/runtime/stpd/ChangeLog index 2a45cdce..858f4e66 100644 --- a/runtime/stpd/ChangeLog +++ b/runtime/stpd/ChangeLog @@ -1,3 +1,9 @@ +2006-12-11 Martin Hunt <hunt@redhat.com> + + * symbols.c (get_sections): Set buffer sizes to large enough + sizes to hold all possible values, but also include checks in case + we are wrong. + 2006-11-15 Martin Hunt <hunt@redhat.com> * symbols.c (do_kernel_symbols): Add sizeof(long) to sym_base diff --git a/runtime/stpd/symbols.c b/runtime/stpd/symbols.c index 8533f4f8..26c9bb1d 100644 --- a/runtime/stpd/symbols.c +++ b/runtime/stpd/symbols.c @@ -21,11 +21,15 @@ static int send_data(void *data, int len) /* in the following order: */ /* [struct _stp_module][struct _stp_symbol sections ...][string data] */ /* Return the total length of all the data. */ + +#define SECDIR "/sys/module/%s/sections" static int get_sections(char *name, char *data_start, int datalen) { - char dir[64], filename[64], buf[32], strdata_start[2048]; + char dir[STP_MODULE_NAME_LEN + sizeof(SECDIR)]; + char filename[STP_MODULE_NAME_LEN + 256]; + char buf[32], strdata_start[4096]; char *strdata=strdata_start, *data=data_start; - int fd, len; + int fd, len, res; struct _stp_module *mod = (struct _stp_module *)data_start; struct dirent *d; DIR *secdir; @@ -34,7 +38,13 @@ static int get_sections(char *name, char *data_start, int datalen) /* start of data is a struct _stp_module */ data += sizeof(struct _stp_module); - sprintf(dir,"/sys/module/%s/sections", name); + res = snprintf(dir, sizeof(dir), SECDIR, name); + if (res >= sizeof(dir)) { + fprintf(stderr, "ERROR: couldn't fit module \"%s\" into dir buffer.\n", name); + fprintf(stderr, "This should never happen. Please file a bug report.\n"); + cleanup_and_exit(0); + } + if ((secdir = opendir(dir)) == NULL) return 0; @@ -43,7 +53,13 @@ static int get_sections(char *name, char *data_start, int datalen) while ((d = readdir(secdir))) { char *secname = d->d_name; - sprintf(filename,"/sys/module/%s/sections/%s", name,secname); + res = snprintf(filename, sizeof(filename), "/sys/module/%s/sections/%s", name, secname); + if (res >= sizeof(filename)) { + fprintf(stderr, "ERROR: couldn't fit secname \"%s\" into filename buffer.\n", secname); + fprintf(stderr, "This should never happen. Please file a bug report.\n"); + closedir(secdir); + cleanup_and_exit(0); + } if ((fd = open(filename,O_RDONLY)) >= 0) { if (read(fd, buf, 32) > 0) { /* filter out some non-useful stuff */ @@ -92,7 +108,7 @@ static int get_sections(char *name, char *data_start, int datalen) return data - data_start; } - +#undef SECDIR void send_module (char *modname) { |