1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-12-23 00:08:50 -05:00

Disallow a NULL section in _parseconfig

If we allow _parseconfig to continue processing when section is not defined,
then we have the potential to segfault during strcmp calls. This is no good.
For some reason, we had existing logic that tested this case but only if it
was processing and 'Include' directive. Expand the check to check for a NULL
section in all cases, and print an error message if this is the case.

Reported here:
http://bbs.archlinux.org/viewtopic.php?id=42235

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2008-01-13 14:14:34 -06:00
parent 8186dc11a9
commit 549c2878f9

View File

@ -606,8 +606,8 @@ static int _parseconfig(const char *file, const char *givensection,
* follow the toupper() rules we may expect, e.g. tr_TR where i != I.
*/
upperkey = strtoupper(strdup(key));
if(section == NULL && (strcmp(key, "Include") == 0 || strcmp(upperkey, "INCLUDE") == 0)) {
pm_printf(PM_LOG_ERROR, _("config file %s, line %d: 'Include' directive must belong to a section.\n"),
if(section == NULL) {
pm_printf(PM_LOG_ERROR, _("config file %s, line %d: All directives must belong to a section.\n"),
file, linenum);
return(1);
}