]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Fix compilation variable in var.c and expand.c
authorEric Bollengier <eric@baculasystems.com>
Thu, 20 Mar 2025 10:39:05 +0000 (11:39 +0100)
committerEric Bollengier <eric@baculasystems.com>
Mon, 24 Mar 2025 07:09:02 +0000 (08:09 +0100)
The original library has the same issue, it returns
local or static variables in some cases.

bacula/src/dird/expand.c
bacula/src/lib/var.c

index b07f52bf43b6faad3b0baf6cd4ae9366f130a5a5..750419d6423fe8badc4a2939cdd76e405b7b1594 100644 (file)
@@ -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;
    }
 
index 51f479014e019bd4d7e103af20a6c72fcba21d37..12980bf9cafb4405bd10632ab54b8dc4f4da9dac 100644 (file)
@@ -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;
     }