Commit 6eb1b44d authored by Philip Carns's avatar Philip Carns

safety checks to separate metadata entries with newlines


git-svn-id: https://svn.mcs.anl.gov/repos/darshan/trunk@823 3b7491f3-a168-0410-bf4b-c445ed680a29
parent 7e2f00c2
...@@ -132,7 +132,19 @@ void add_annotation (char *annotation, ...@@ -132,7 +132,19 @@ void add_annotation (char *annotation,
{ {
char *token; char *token;
char *save; char *save;
int len;
/* check for newline in existing metadata, insert if needed */
len = strlen(job->metadata);
if(len > 0 && len < sizeof(job->metadata))
{
if(job->metadata[len-1] != '\n')
{
job->metadata[len] = '\n';
job->metadata[len+1] = '\0';
}
}
/* determine remaining space in metadata string */ /* determine remaining space in metadata string */
int remaining = sizeof(job->metadata) - strlen(job->metadata); int remaining = sizeof(job->metadata) - strlen(job->metadata);
......
...@@ -452,6 +452,7 @@ int darshan_log_putjob(darshan_fd file, struct darshan_job *job) ...@@ -452,6 +452,7 @@ int darshan_log_putjob(darshan_fd file, struct darshan_job *job)
struct darshan_job job_copy; struct darshan_job job_copy;
char pv_str[64]; char pv_str[64];
int ret; int ret;
int len;
ret = darshan_log_seek(file, 0); ret = darshan_log_seek(file, 0);
if(ret < 0) if(ret < 0)
...@@ -459,6 +460,17 @@ int darshan_log_putjob(darshan_fd file, struct darshan_job *job) ...@@ -459,6 +460,17 @@ int darshan_log_putjob(darshan_fd file, struct darshan_job *job)
memset(&job_copy, 0, sizeof(job_copy)); memset(&job_copy, 0, sizeof(job_copy));
memcpy(&job_copy, job, sizeof(job_copy)); memcpy(&job_copy, job, sizeof(job_copy));
/* check for newline in existing metadata, add if needed */
len = strlen(job_copy.metadata);
if(len > 0 && len < DARSHAN_JOB_METADATA_LEN)
{
if(job_copy.metadata[len-1] != '\n')
{
job_copy.metadata[len] = '\n';
job_copy.metadata[len+1] = '\0';
}
}
sprintf(pv_str, "prev_ver=%s\n", job->version_string); sprintf(pv_str, "prev_ver=%s\n", job->version_string);
sprintf(job_copy.version_string, "%s", CP_VERSION); sprintf(job_copy.version_string, "%s", CP_VERSION);
if(strlen(job_copy.metadata) + strlen(pv_str) < DARSHAN_JOB_METADATA_LEN) if(strlen(job_copy.metadata) + strlen(pv_str) < DARSHAN_JOB_METADATA_LEN)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment