Skip to content

Commit

Permalink
bscan: Fix crash when filesettext is null
Browse files Browse the repository at this point in the history
Fixes #573: rsync tape between bareos server
  • Loading branch information
pstorz authored and Marco van Wieringen committed Jan 6, 2016
1 parent a4884e2 commit 3c5810f
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/cats/sql_create.c
Expand Up @@ -734,7 +734,6 @@ bool db_create_fileset_record(JCR *jcr, B_DB *mdb, FILESET_DBR *fsr)
int num_rows, len;
char esc_fs[MAX_ESCAPE_NAME_LENGTH];
char esc_md5[MAX_ESCAPE_NAME_LENGTH];
POOL_MEM esc_filesettext(PM_MESSAGE);

db_lock(mdb);
fsr->created = false;
Expand Down Expand Up @@ -772,23 +771,31 @@ bool db_create_fileset_record(JCR *jcr, B_DB *mdb, FILESET_DBR *fsr)
sql_free_result(mdb);
}

/*
* Must create it
*/
if (fsr->CreateTime == 0 && fsr->cCreateTime[0] == 0) {
fsr->CreateTime = time(NULL);
}

bstrutime(fsr->cCreateTime, sizeof(fsr->cCreateTime), fsr->CreateTime);
if (fsr->FileSetText) {
POOL_MEM esc_filesettext(PM_MESSAGE);

len = strlen(fsr->FileSetText);
esc_filesettext.check_size(len * 2 + 1);
mdb->db_escape_string(jcr, esc_filesettext.c_str(), fsr->FileSetText, len);
len = strlen(fsr->FileSetText);
esc_filesettext.check_size(len * 2 + 1);
mdb->db_escape_string(jcr, esc_filesettext.c_str(), fsr->FileSetText, len);

/*
* Must create it
*/
Mmsg(mdb->cmd,
"INSERT INTO FileSet (FileSet,MD5,CreateTime,FileSetText) "
"VALUES ('%s','%s','%s','%s')",
esc_fs, esc_md5, fsr->cCreateTime, esc_filesettext.c_str());
Mmsg(mdb->cmd,
"INSERT INTO FileSet (FileSet,MD5,CreateTime,FileSetText) "
"VALUES ('%s','%s','%s','%s')",
esc_fs, esc_md5, fsr->cCreateTime, esc_filesettext.c_str());
} else {
Mmsg(mdb->cmd,
"INSERT INTO FileSet (FileSet,MD5,CreateTime) "
"VALUES ('%s','%s','%s')",
esc_fs, esc_md5, fsr->cCreateTime);
}

fsr->FileSetId = sql_insert_autokey_record(mdb, mdb->cmd, NT_("FileSet"));
if (fsr->FileSetId == 0) {
Expand Down

0 comments on commit 3c5810f

Please sign in to comment.