View Issue Details

IDProjectCategoryView StatusLast Update
0009291GNUnetutil librarypublic2024-10-29 20:56
Reporterfefe Assigned Toschanzen  
PrioritynormalSeverityminorReproducibilityhave not tried
Status closedResolutionno change required 
Target Version0.22.2Fixed in Version0.22.2 
Summary0009291: GNUNET_CONFIGURATION_serialize: confused code
Description  1190 len = GNUNET_asprintf (&cbuf,
  1191 "[%s]\n",
  1192 sec->name);
  1193 GNUNET_assert (0 < len);
  1194 GNUNET_memcpy (mem + c_size,
  1195 cbuf,
  1196 len);
  1197 c_size += len;
  1198 GNUNET_free (cbuf);

Just call GNUNET_vsnprintf and skip the memory allocation and deallocation.
You even gain a buffer overflow check that way.

Same advice applies further down in the same function:

  1216 len = GNUNET_asprintf (&cbuf, "%s = %s\n", ent->key, val);
  1217 GNUNET_free (val);
  1218 GNUNET_memcpy (mem + c_size, cbuf, len);
  1219 c_size += len;
  1220 GNUNET_free (cbuf);

I would, in fact, recommend refactoring the whole function. It does things in a very inefficient way (using memmove repeatedly to escape \n to \\n).
TagsNo tags attached.

Relationships

related to 0009286 closedschanzen GNUNET_asprintf: don't call vsprintf 

Activities

schanzen

2024-10-23 21:19

administrator   ~0023578

Not sure what exactly to do here. GNUNET_vsnprintf does not exists. vsnprintf requires us to pre-allocate the buffer. We can do that, of course, but I see no benefit as this is not a performance-critical function.

schanzen

2024-10-25 15:33

administrator   ~0023601

Also GNUNET_asprintf already calls vsnprintf 0009286

schanzen

2024-10-29 13:17

administrator   ~0023615

GNUNET_asprintf already calls vsnprintf only. Refactoring/improvement of GNUNET_CONFIGURATION_serialize is not clear enough and requires a new issue with more detailed targeted description.

schanzen

2024-10-29 20:56

administrator   ~0023623

Released

Issue History

Date Modified Username Field Change
2024-10-22 16:14 fefe New Issue
2024-10-23 13:19 schanzen Target Version => 0.22.2
2024-10-23 21:19 schanzen Note Added: 0023578
2024-10-25 15:33 schanzen Note Added: 0023601
2024-10-25 15:33 schanzen Relationship added related to 0009286
2024-10-29 13:17 schanzen Assigned To => schanzen
2024-10-29 13:17 schanzen Status new => resolved
2024-10-29 13:17 schanzen Resolution open => no change required
2024-10-29 13:17 schanzen Fixed in Version => 0.22.2
2024-10-29 13:17 schanzen Note Added: 0023615
2024-10-29 20:56 schanzen Note Added: 0023623
2024-10-29 20:56 schanzen Status resolved => closed