Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[settings] Ensure fetch_string_setting() returns a NUL-terminated string
This fixes a regression introduced in commit 612f4e7:

  [settings] Avoid returning uninitialised data on error in fetch_xxx_setting()

in which the memset() was moved from fetch_string_setting() to
fetch_setting(), in order that it would be useful for non-string
setting types.  However, this neglects to take into account the fact
that fetch_string_setting() shrinks its buffer by one byte (to allow
for the NUL) before calling fetch_setting().

Restore the memset() in fetch_string_setting(), so that the
terminating NUL is guaranteed to actually be a NUL.
  • Loading branch information
Michael Brown committed Nov 7, 2008
1 parent 29e6f98 commit ed196a3
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/core/settings.c
Expand Up @@ -384,6 +384,7 @@ int fetch_setting_len ( struct settings *settings, struct setting *setting ) {
*/
int fetch_string_setting ( struct settings *settings, struct setting *setting,
char *data, size_t len ) {
memset ( data, 0, len );
return fetch_setting ( settings, setting, data,
( ( len > 0 ) ? ( len - 1 ) : 0 ) );
}
Expand Down

0 comments on commit ed196a3

Please sign in to comment.