From 0791a530217a2ba46a7565382aa56135e07ea926 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Sat, 30 Jan 2010 08:48:11 +0100 Subject: [PATCH] Fix seg fault in SQlite driver --- bacula/src/cats/sqlite.c | 7 +++++++ bacula/src/lib/bsys.c | 3 +++ 2 files changed, 10 insertions(+) diff --git a/bacula/src/cats/sqlite.c b/bacula/src/cats/sqlite.c index 1672f07502..93d4196ae3 100644 --- a/bacula/src/cats/sqlite.c +++ b/bacula/src/cats/sqlite.c @@ -448,6 +448,13 @@ void my_sqlite_field_seek(B_DB *mdb, int field) mdb->fields = (SQL_FIELD **)malloc(sizeof(SQL_FIELD) * mdb->ncolumn); for (i=0; i < sql_num_fields(mdb); i++) { mdb->fields[i] = (SQL_FIELD *)malloc(sizeof(SQL_FIELD)); + if (mdb->result[i] == NULL) { + mdb->fields_defined = false; + free(mdb->fields); + mdb->fields = NULL; + mdb->field = 0; + return; + } mdb->fields[i]->name = mdb->result[i]; mdb->fields[i]->length = cstrlen(mdb->fields[i]->name); mdb->fields[i]->max_length = mdb->fields[i]->length; diff --git a/bacula/src/lib/bsys.c b/bacula/src/lib/bsys.c index fe86199db3..f5d7bc6a7a 100644 --- a/bacula/src/lib/bsys.c +++ b/bacula/src/lib/bsys.c @@ -160,6 +160,9 @@ int cstrlen(const char *str) { uint8_t *p = (uint8_t *)str; int len = 0; + if (str == NULL) { + return 0; + } while (*p) { if ((*p & 0xC0) != 0xC0) { p++; -- 2.39.5