1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
From: Simon Chopin <simon.chopin@canonical.com>
Date: Fri, 22 Mar 2024 17:43:22 +0100
Subject: [PATCH] Fix printf specifiers for time_t-related types
Best to only use fixed-width types and explicit casting.
---
nasl/nasl_misc_funcs.c | 3 ++-
src/attack.c | 22 +++++++++++-----------
src/pluginlaunch.c | 8 +++++---
3 files changed, 18 insertions(+), 15 deletions(-)
diff --git a/nasl/nasl_misc_funcs.c b/nasl/nasl_misc_funcs.c
index c9b908f..d9286e7 100644
--- a/nasl/nasl_misc_funcs.c
+++ b/nasl/nasl_misc_funcs.c
@@ -30,6 +30,7 @@
#include <glib.h>
#include <gvm/util/compressutils.h> /* for gvm_uncompress */
#include <gvm/util/kb.h> /* for KB_TYPE_STR */
+#include <inttypes.h>
#include <stdbool.h> /* for boolean */
#include <stdlib.h> /* for lrand48 */
#include <string.h> /* for bzero */
@@ -657,7 +658,7 @@ nasl_gettimeofday (lex_ctxt *lexic)
nasl_perror (lexic, "gettimeofday: %s\n", strerror (errno));
return NULL;
}
- sprintf (str, "%u.%06u", (unsigned int) t.tv_sec, (unsigned int) t.tv_usec);
+ sprintf (str, "%"PRIu64".%06"PRIu32, (uint64_t) t.tv_sec, (uint32_t) t.tv_usec);
retc = alloc_typed_cell (CONST_DATA);
retc->size = strlen (str);
retc->x.str_val = g_malloc0 (retc->size);
diff --git a/src/attack.c b/src/attack.c
index 8779c45..12395fc 100644
--- a/src/attack.c
+++ b/src/attack.c
@@ -45,9 +45,11 @@
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
+#include <stdint.h>
#include <string.h> /* for strlen() */
#include <sys/wait.h> /* for waitpid() */
#include <unistd.h> /* for close() */
+#include <inttypes.h>
#define ERR_HOST_DEAD -1
@@ -908,9 +910,9 @@ attack_start (struct ipc_context *ipcc, struct attack_start_args *args)
now.tv_usec += 1000000;
}
g_message (
- "Vulnerability scan %s finished for host %s in %ld.%.2ld seconds",
- globals->scan_id, ip_str, (long) (now.tv_sec - then.tv_sec),
- (long) ((now.tv_usec - then.tv_usec) / 10000));
+ "Vulnerability scan %s finished for host %s in %"PRIu64".%.2"PRIu32" seconds",
+ globals->scan_id, ip_str, (uint64_t) (now.tv_sec - then.tv_sec),
+ (uint32_t) ((now.tv_usec - then.tv_usec) / 10000));
}
}
@@ -1554,15 +1556,13 @@ stop:
gettimeofday (&now, NULL);
if (test_alive_hosts_only)
- {
- g_message ("Vulnerability scan %s finished in %ld seconds: "
- "%d alive hosts of %d",
- globals->scan_id, now.tv_sec - then.tv_sec,
- gvm_hosts_count (alive_hosts_list), gvm_hosts_count (hosts));
- }
- else
- g_message ("Vulnerability scan %s finished in %ld seconds: %d hosts",
+ g_message ("Vulnerability scan %s finished in %"PRIu64" seconds: "
+ "%d alive hosts of %d",
globals->scan_id, now.tv_sec - then.tv_sec,
+ gvm_hosts_count (alive_hosts_list), gvm_hosts_count (hosts));
+ else
+ g_message ("Vulnerability scan %s finished in %"PRIu64" seconds: %d hosts",
+ globals->scan_id, (uint64_t)(now.tv_sec - then.tv_sec),
gvm_hosts_count (hosts));
if (prefs_get ("report_scripts"))
diff --git a/src/pluginlaunch.c b/src/pluginlaunch.c
index fd52ad0..cb436f4 100644
--- a/src/pluginlaunch.c
+++ b/src/pluginlaunch.c
@@ -24,8 +24,10 @@
#include "utils.h"
#include <errno.h> /* for errno() */
+#include <inttypes.h>
#include <gvm/base/prefs.h> /* for prefs_get_bool() */
#include <gvm/util/nvticache.h>
+#include <stdint.h>
#include <stdio.h> /* for perror() */
#include <stdlib.h> /* for atoi() */
#include <string.h>
@@ -188,10 +190,10 @@ update_running_processes (kb_t main_kb, kb_t kb)
{
char *name = nvticache_get_filename (oid);
g_message (
- "%s (%s) [%d] finished its job in %ld.%.3ld seconds",
+ "%s (%s) [%d] finished its job in %"PRIu64".%.3"PRIu32" seconds",
name, oid, processes[i].pid,
- (long) (now.tv_sec - processes[i].start.tv_sec),
- (long) ((now.tv_usec - processes[i].start.tv_usec)
+ (uint64_t) (now.tv_sec - processes[i].start.tv_sec),
+ (uint32_t) ((now.tv_usec - processes[i].start.tv_usec)
/ 1000));
g_free (name);
|