Bug 110847

Summary: occlusion-query.c:190:45: error: format specifies type 'unsigned long' but the argument has type 'uint64_t' (aka 'unsigned long long') [-Werror,-Wformat]
Product: Mesa Reporter: Vinson Lee <vlee>
Component: OtherAssignee: Mark Janes <mark.a.janes>
Status: RESOLVED FIXED QA Contact: mesa-dev
Severity: normal    
Priority: medium CC: mark.a.janes
Version: unspecifiedKeywords: bisected, regression
Hardware: x86-64 (AMD64)   
OS: All   
Whiteboard:
i915 platform: i915 features:

Description Vinson Lee 2019-06-06 02:20:36 UTC
../src/gallium/tests/graw/occlusion-query.c:190:45: error: format specifies type 'unsigned long' but the argument has type 'uint64_t' (aka 'unsigned long long') [-Werror,-Wformat]
   printf("result1 = %lu  result2 = %lu\n", res1.u64, res2.u64);
                     ~~~                    ^~~~~~~~
                     %llu


commit c9c1e26106478258d8a91fe8fc5c69d8c3fa5206
Author: Mark Janes <mark.a.janes@intel.com>
Date:   Mon Jun 3 16:59:45 2019 -0700

    mesa: prevent common string formatting security issues
    
    Adds a compile-time error for obvious security issues like:
    
      printf(string_var);
    
    The proposed flag is more tolerant than -Wformat-nonliteral.
    Specifically, it tolerates common mesa formatting like:
    
      static const char *shader_template = "really long string %d";
      printf(shader_template, uniform_number);
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=110833
    Reviewed-by: Eric Anholt <eric@anholt.net>
    Reviewed-by: Eric Engestrom <eric@engestrom.ch>
Comment 1 Mark Janes 2019-06-06 05:53:17 UTC
Vinson: I don't know how to reproduce this build error, but I think this patch should fix it:

https://gitlab.freedesktop.org/majanes/mesa/commit/c421d1533f86c5bcd18974164c4e8bf2457e7b96

Can you test the patch and let me know if there are any other printf security issues in your build configuration?
Comment 2 Mark Janes 2019-06-06 06:01:07 UTC
Oops, I guess it needs an include also:

  https://gitlab.freedesktop.org/majanes/mesa/commit/97e056faf38ff65274dd91e2a1d29ae7859c1c51
Comment 3 Emil Velikov 2019-06-06 10:06:56 UTC
(In reply to Mark Janes from comment #2)
> Oops, I guess it needs an include also:
> 
>  
> https://gitlab.freedesktop.org/majanes/mesa/commit/
> 97e056faf38ff65274dd91e2a1d29ae7859c1c51


Patch looks spot-on. Feel free to add my r-b when sending it for inclusion.

Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Comment 4 Mark Janes 2019-06-07 00:13:47 UTC
Fixed by:

04dac6975234d3b4e5da6aa61e6b787cb576f0e6
Author:     Mark Janes <mark.a.janes@intel.com>

tests/graw: use C99 print conversion specifier for 32 bit builds

Fixes formatting errors for 32 bit compilations, eg:

  error: format specifies type 'unsigned long' but the argument has
  type 'uint64_t' (aka 'unsigned long long') [-Werror,-Wformat]
  printf("result1 = %lu result2 = %lu\n", res1.u64, res2.u64);

Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Eric Anholt <eric@anholt.net>

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.