POSTGRESQL_ROW row;
POSTGRESQL_FIELD *fields;
int num_rows;
+ int row_size; /* size of malloced rows */
int num_fields;
- int row_number; /* what row number did we get via my_postgresql_data_seek? */
- int field_number; /* what field number did we get via my_postgresql_field_seek? */
+ int fields_size; /* size of malloced fields */
+ int row_number; /* row number from my_postgresql_data_seek */
+ int field_number; /* field number from my_postgresql_field_seek */
int ref_count;
char *db_name;
char *db_user;
Dmsg0(500, "my_postgresql_fetch_row start\n");
- if (mdb->row_number == -1 || mdb->row == NULL) {
+ if (!mdb->row || mdb->row_size < mdb->num_fields) {
Dmsg1(500, "we have need space of %d bytes\n", sizeof(char *) * mdb->num_fields);
- if (mdb->row != NULL) {
+ if (mdb->row) {
Dmsg0(500, "my_postgresql_fetch_row freeing space\n");
free(mdb->row);
- mdb->row = NULL;
}
-
mdb->row = (POSTGRESQL_ROW) malloc(sizeof(char *) * mdb->num_fields);
+ mdb->row_size = mdb->num_fields;
// now reset the row_number now that we have the space allocated
mdb->row_number = 0;
int i;
Dmsg0(500, "my_postgresql_fetch_field starts\n");
- if (mdb->fields == NULL) {
+
+ if (!mdb->fields || mdb->fields_size < mdb->num_fields) {
+ if (mdb->fields) {
+ free(mdb->fields);
+ }
Dmsg1(500, "allocating space for %d fields\n", mdb->num_fields);
mdb->fields = (POSTGRESQL_FIELD *)malloc(sizeof(POSTGRESQL_FIELD) * mdb->num_fields);
+ mdb->fields_size = mdb->num_fields;
for (i = 0; i < mdb->num_fields; i++) {
Dmsg1(500, "filling field %d\n", i);
}
/* Check for prefer mounted volumes */
-// if (rctx.PreferMountedVols && !dev->VolHdr.VolumeName[0] && dev->is_tape()) {
if (rctx.PreferMountedVols && !dev->vol && dev->is_tape()) {
Mmsg(jcr->errmsg, _("3606 JobId=%u prefers mounted drives, but drive %s has no Volume.\n"),
jcr->JobId, dev->print_name());
jcr->JobId, rctx.VolumeName, dev->VolHdr.VolumeName,
dev->print_name());
queue_reserve_message(jcr);
- Dmsg4(dbglvl, "JobId=%u failed: dev have=%s resvol=%s want=%s\n",
+ Dmsg4(dbglvl, "JobId=%u not OK: dev have=%s resvol=%s want=%s\n",
(int)jcr->JobId, dev->VolHdr.VolumeName,
dev->vol?dev->vol->vol_name:"*none*", rctx.VolumeName);
return 0;
General:
02Jun07
+kes Fix Bacula PostgreSQL buffer overruns.
kes Do better checking for NULL results returned from PostgreSQL;
implement retry for failed queries; clear results buffer after
failed query. Hopefully this will correct the PostgreSQL failures.