Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[settings] Avoid overwriting the start of .text in fetch_string_setti…
…ng()

fetch_string_setting() was subtracting one from the length of the
to-be-NUL-terminated buffer in order to obtain the length of the
unterminated buffer to be passed to fetch_setting().  This works
extremely well unless the length of the to-be-NUL-terminated buffer is
zero, at which point we end up giving fetch_setting() a buffer of
length -1UL, thereby inviting it to overwrite as much memory as it
wants...
  • Loading branch information
Michael Brown committed Aug 14, 2008
1 parent a1d0f6e commit 8f8f5ac
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/core/settings.c
Expand Up @@ -381,7 +381,8 @@ 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 - 1 ) );
return fetch_setting ( settings, setting, data,
( ( len > 0 ) ? ( len - 1 ) : 0 ) );
}

/**
Expand Down

0 comments on commit 8f8f5ac

Please sign in to comment.