Skip to content

Commit 8711fbd

Browse files
committed
utils: add a len argument to get_current_timestamp
Signed-off-by: Giuseppe Scrivano <[email protected]>
1 parent b5987ee commit 8711fbd

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

src/libcrun/container.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1683,7 +1683,7 @@ write_container_status (libcrun_container_t *container, libcrun_context_t *conte
16831683
.scope = NULL,
16841684
};
16851685

1686-
get_current_timestamp (created);
1686+
get_current_timestamp (created, sizeof (created));
16871687

16881688
if (cwd == NULL)
16891689
OOM ();

src/libcrun/utils.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,7 +1605,7 @@ mark_or_close_fds_ge_than (int n, bool close_now, libcrun_error_t *err)
16051605
}
16061606

16071607
void
1608-
get_current_timestamp (char *out)
1608+
get_current_timestamp (char *out, size_t len)
16091609
{
16101610
struct timeval tv;
16111611
struct tm now;
@@ -1615,7 +1615,8 @@ get_current_timestamp (char *out)
16151615
gmtime_r (&tv.tv_sec, &now);
16161616
strftime (timestamp, sizeof (timestamp), "%Y-%m-%dT%H:%M:%S", &now);
16171617

1618-
sprintf (out, "%s.%09ldZ", timestamp, tv.tv_usec);
1618+
snprintf (out, len, "%s.%09ldZ", timestamp, tv.tv_usec);
1619+
out[len - 1] = '\0';
16191620
}
16201621

16211622
int

src/libcrun/utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ int run_process_with_stdin_timeout_envp (char *path, char **args, const char *cw
302302

303303
int mark_or_close_fds_ge_than (int n, bool close_now, libcrun_error_t *err);
304304

305-
void get_current_timestamp (char *out);
305+
void get_current_timestamp (char *out, size_t len);
306306

307307
int set_blocking_fd (int fd, int blocking, libcrun_error_t *err);
308308

0 commit comments

Comments
 (0)