From: Eric Bollengier Date: Thu, 20 Mar 2025 10:39:05 +0000 (+0100) Subject: Fix compilation variable in var.c and expand.c X-Git-Tag: Release-15.0.3~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9ec34529ea75ecba55b19c924bd30e8b6a0b54a3;p=thirdparty%2Fbacula.git Fix compilation variable in var.c and expand.c The original library has the same issue, it returns local or static variables in some cases. --- diff --git a/bacula/src/dird/expand.c b/bacula/src/dird/expand.c index b07f52bf4..750419d64 100644 --- a/bacula/src/dird/expand.c +++ b/bacula/src/dird/expand.c @@ -220,13 +220,13 @@ static var_rc_t lookup_counter_var(var_t *ctx, void *my_ctx, LockRes(); for (COUNTER *counter=NULL; (counter = (COUNTER *)GetNextRes(R_COUNTER, (RES *)counter)); ) { if (strcmp(counter->name(), buf) == 0) { - Dmsg2(100, "Counter=%s val=%d\n", buf, counter->CurrentValue); + Dmsg3(100, "Counter=%s val=%d var_index=%d\n", buf, counter->CurrentValue, var_index); /* -1 => return size of array */ if (var_index == -1) { bsnprintf(buf, sizeof(buf), "%d", counter->CurrentValue); *val_len = bsnprintf(buf, sizeof(buf), "%d", strlen(buf)); - *val_ptr = buf; - *val_size = 0; /* don't try to free val_ptr */ + *val_ptr = bstrdup(buf); + *val_size = *val_len+1; return VAR_OK; } else { bsnprintf(buf, sizeof(buf), "%d", counter->CurrentValue); @@ -324,8 +324,8 @@ static var_rc_t lookup_var(var_t *ctx, void *my_ctx, len = count; /* else return # array items */ } *val_len = bsnprintf(buf, sizeof(buf), "%d", len); - *val_ptr = buf; - *val_size = 0; /* don't try to free val_ptr */ + *val_ptr = bstrdup(buf); + *val_size = *val_len+1; return VAR_OK; } diff --git a/bacula/src/lib/var.c b/bacula/src/lib/var.c index 51f479014..12980bf9c 100644 --- a/bacula/src/lib/var.c +++ b/bacula/src/lib/var.c @@ -1850,7 +1850,6 @@ lookup_value( const char *var_ptr, int var_len, int var_inc, int var_idx, const char **val_ptr, int *val_len, int *val_size) { - char buf[1]; int rc; /* pass through to original callback */ @@ -1865,11 +1864,9 @@ lookup_value( This trick here allows it to determine this case. */ if (ctx->rel_lookup_flag && rc == VAR_ERR_UNDEFINED_VARIABLE) { ctx->rel_lookup_cnt--; - buf[0] = EOS; - /* ****FIXME**** passing back stack variable!!! */ - *val_ptr = buf; + *val_ptr = bstrdup(""); *val_len = 0; - *val_size = 0; + *val_size = 1; return VAR_OK; }