View Issue Details

IDProjectCategoryView StatusLast Update
0006197Talerexchangepublic2020-04-23 15:39
Reporterfefe Assigned ToChristian Grothoff  
PrioritynormalSeverityminorReproducibilityhave not tried
Status closedResolutionno change required 
Product Version0.7.0 
Target Version0.7.1Fixed in Version0.7.1 
Summary0006197: TALER_MHD_handle_logs is not thread-safe
DescriptionThe code for TALER_MHD_handle_logs is in exchange/src/mhd/mhd_config.c.
It does this:

173 static int cache;

177 if (-1 == cache)
178 return;
179 if (0 == cache)
180 {
181 if (0 ==
182 GNUNET_get_log_call_status (GNUNET_ERROR_TYPE_INFO,
183 "libmicrohttpd",
184 __FILE__,
185 __FUNCTION__,
186 __LINE__))
187 {
188 cache = -1;
189 return;
190 }
191 }
192 cache = 1;

This is not thread-safe. Since the function is called from a different software module, it should make no assumptions about being only called from a single thread.

Use pthread_once or mutexes or atomic instructions.
TagsNo tags attached.

Activities

Christian Grothoff

2020-04-22 15:14

manager   ~0015732

GNUNET_get_log_call_status can be shown to always return the same result given the same inputs. Hence, a race on 'once' does not matter, as both will compute the same result. Adding locking around such a fast computation that is pretty harmless if executed twice _or_ executing it once per thread (and requiring extra RAM) seem to be all worse, or even pointless.

Note that MHD even includes an _intentional_ race. IMO, not all races are bad, if one can show (like in this case), that all execution orders result in sane, safe behavior.

fefe

2020-04-23 15:36

developer   ~0015765

OK. I just wanted you to be aware of this pattern. :)

Christian Grothoff

2020-04-23 15:38

manager   ~0015768

Oh, I am. It exists in *every* GNUNET_log(), GNUNET_assert(), GNUNET_break() in the code...

Issue History

Date Modified Username Field Change
2020-04-22 12:35 fefe New Issue
2020-04-22 12:35 fefe Status new => assigned
2020-04-22 12:35 fefe Assigned To => Christian Grothoff
2020-04-22 15:14 Christian Grothoff Note Added: 0015732
2020-04-22 15:14 Christian Grothoff Status assigned => feedback
2020-04-22 15:46 Christian Grothoff Assigned To Christian Grothoff =>
2020-04-23 15:36 fefe Note Added: 0015765
2020-04-23 15:36 fefe Status feedback => new
2020-04-23 15:38 Christian Grothoff Note Added: 0015768
2020-04-23 15:39 Christian Grothoff Assigned To => Christian Grothoff
2020-04-23 15:39 Christian Grothoff Status new => closed
2020-04-23 15:39 Christian Grothoff Resolution open => no change required
2020-04-23 15:39 Christian Grothoff Fixed in Version => 0.7.1
2020-04-23 15:39 Christian Grothoff Target Version => 0.7.1