Avoid passing NULL as format parameter 03/295003/1 accepted/tizen_unified_dev accepted/tizen/unified/dev/20230726.115516
authorŁukasz Stelmach <l.stelmach@samsung.com>
Thu, 29 Jun 2023 11:05:23 +0000 (13:05 +0200)
committerŁukasz Stelmach <l.stelmach@samsung.com>
Thu, 29 Jun 2023 11:08:39 +0000 (13:08 +0200)
GCC reported possible problem with passing NULL returned from
*_to_string() helpers as an argument for '%s' in a format string.

../src/core/job.c: In function 'job_finish_and_invalidate':
../src/core/job.c:976:27: error: '%s' directive argument is null [-Werror=format-overflow=]
  976 |         log_unit_debug(u, "Job %" PRIu32 " %s/%s finished, result=%s", j->id, u->id, job_type_to_string(t), job_result_to_string(result));
      |                           ^~~~~~~
../src/core/unit.h:878:190: note: in definition of macro 'log_unit_full'
  878 |                 _u ? log_object_internal(level, error, PROJECT_FILE, __LINE__, __func__, _u->manager->unit_log_field, _u->id, _u->manager->invocation_log_field, _u->invocation_id_string, ##__VA_ARGS__) : \
      |                                                                                                                                                                                              ^~~~~~~~~~~
../src/core/job.c:976:9: note: in expansion of macro 'log_unit_debug'
  976 |         log_unit_debug(u, "Job %" PRIu32 " %s/%s finished, result=%s", j->id, u->id, job_type_to_string(t), job_result_to_string(result));
      |         ^~~~~~~~~~~~~~

Wrapping the helpers in strna() prevents this from happening.

Further fixes may be applied depending on the outcomes of the discussion
on the systemd-devel mailing list.

Change-Id: Id73f2bc887f46bb07fc960d264953cd5dfce82de
Link: https://lists.freedesktop.org/archives/systemd-devel/2023-June/049215.html
Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
src/core/job.c

index 5048a50..ffd7cd8 100644 (file)
@@ -973,7 +973,9 @@ int job_finish_and_invalidate(Job *j, JobResult result, bool recursive, bool alr
 
         j->result = result;
 
-        log_unit_debug(u, "Job %" PRIu32 " %s/%s finished, result=%s", j->id, u->id, job_type_to_string(t), job_result_to_string(result));
+        log_unit_debug(u, "Job %" PRIu32 " %s/%s finished, result=%s",
+                       j->id, u->id, strna(job_type_to_string(t)),
+                       strna(job_result_to_string(result)));
 
         /* If this job did nothing to respective unit we don't log the status message */
         if (!already)