Skip to content

Commit bf72edb

Browse files
authored
Merge pull request #1735 from eriksjolund/fix-getcwd-error-handling
Fix getcwd error handling
2 parents b812ced + ffbfb6f commit bf72edb

File tree

5 files changed

+14
-7
lines changed

5 files changed

+14
-7
lines changed

src/checkpoint.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ crun_command_checkpoint (struct crun_global_arguments *global_args, int argc, ch
199199

200200
path = getcwd (NULL, 0);
201201
if (UNLIKELY (path == NULL))
202-
libcrun_fail_with_error (0, "realloc failed");
202+
libcrun_fail_with_error (errno, "getcwd failed");
203203

204204
ret = asprintf (&cr_path, "%s/checkpoint", path);
205205
if (UNLIKELY (ret < 0))

src/create.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,11 @@ crun_command_create (struct crun_global_arguments *global_args, int argc, char *
139139

140140
/* Make sure the bundle is an absolute path. */
141141
if (bundle == NULL)
142-
bundle = bundle_cleanup = getcwd (NULL, 0);
142+
{
143+
bundle = bundle_cleanup = getcwd (NULL, 0);
144+
if (UNLIKELY (bundle == NULL))
145+
libcrun_fail_with_error (errno, "getcwd failed");
146+
}
143147
else
144148
{
145149
if (bundle[0] != '/')

src/libcrun/container.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -1847,6 +1847,8 @@ write_container_status (libcrun_container_t *container, libcrun_context_t *conte
18471847
libcrun_error_t *err)
18481848
{
18491849
cleanup_free char *cwd = getcwd (NULL, 0);
1850+
if (UNLIKELY (cwd == NULL))
1851+
libcrun_fail_with_error (errno, "getcwd failed");
18501852
cleanup_free char *owner = get_user_name (geteuid ());
18511853
cleanup_free char *intelrdt = NULL;
18521854
char *external_descriptors = libcrun_get_external_descriptors (container);
@@ -1883,9 +1885,6 @@ write_container_status (libcrun_container_t *container, libcrun_context_t *conte
18831885

18841886
get_current_timestamp (created, sizeof (created));
18851887

1886-
if (cwd == NULL)
1887-
OOM ();
1888-
18891888
if (cgroup_status)
18901889
{
18911890
int ret;

src/restore.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ crun_command_restore (struct crun_global_arguments *global_args, int argc, char
195195

196196
path = getcwd (NULL, 0);
197197
if (UNLIKELY (path == NULL))
198-
libcrun_fail_with_error (0, "realloc failed");
198+
libcrun_fail_with_error (errno, "getcwd failed");
199199

200200
ret = asprintf (&cr_path, "%s/checkpoint", path);
201201
if (UNLIKELY (ret < 0))

src/run.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,11 @@ crun_command_run (struct crun_global_arguments *global_args, int argc, char **ar
151151

152152
/* Make sure the bundle is an absolute path. */
153153
if (bundle == NULL)
154-
bundle = bundle_cleanup = getcwd (NULL, 0);
154+
{
155+
bundle = bundle_cleanup = getcwd (NULL, 0);
156+
if (UNLIKELY (bundle == NULL))
157+
libcrun_fail_with_error (errno, "getcwd failed");
158+
}
155159
else
156160
{
157161
if (bundle[0] != '/')

0 commit comments

Comments
 (0)