Fix a leak in the code that parses the protocol names.
Also added some comments. Reported by Ben Gamari (bug #16492).
This commit is contained in:
parent
a4cb25f8c8
commit
a3ec226273
|
@ -126,10 +126,12 @@ RegisterExtensionNames(ExtensionEntry *extEntry)
|
||||||
rewind(fh);
|
rewind(fh);
|
||||||
|
|
||||||
while (fgets(buf, sizeof(buf), fh)) {
|
while (fgets(buf, sizeof(buf), fh)) {
|
||||||
|
lineobj = NULL;
|
||||||
ptr = strchr(buf, '\n');
|
ptr = strchr(buf, '\n');
|
||||||
if (ptr)
|
if (ptr)
|
||||||
*ptr = 0;
|
*ptr = 0;
|
||||||
|
|
||||||
|
/* Check for comments or empty lines */
|
||||||
switch (buf[0]) {
|
switch (buf[0]) {
|
||||||
case PROT_REQUEST:
|
case PROT_REQUEST:
|
||||||
case PROT_EVENT:
|
case PROT_EVENT:
|
||||||
|
@ -139,48 +141,54 @@ RegisterExtensionNames(ExtensionEntry *extEntry)
|
||||||
case '\0':
|
case '\0':
|
||||||
continue;
|
continue;
|
||||||
default:
|
default:
|
||||||
continue;
|
goto invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check for space character in the fifth position */
|
||||||
ptr = strchr(buf, ' ');
|
ptr = strchr(buf, ' ');
|
||||||
if (!ptr || ptr != buf + 4) {
|
if (!ptr || ptr != buf + 4)
|
||||||
LogMessage(X_WARNING, "Invalid line in " FILENAME ", skipping\n");
|
goto invalid;
|
||||||
continue;
|
|
||||||
}
|
/* Duplicate the string after the space */
|
||||||
lineobj = strdup(ptr + 1);
|
lineobj = strdup(ptr + 1);
|
||||||
if (!lineobj)
|
if (!lineobj)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
/* Check for a colon somewhere on the line */
|
||||||
ptr = strchr(buf, ':');
|
ptr = strchr(buf, ':');
|
||||||
if (!ptr) {
|
if (!ptr)
|
||||||
LogMessage(X_WARNING, "Invalid line in " FILENAME ", skipping\n");
|
goto invalid;
|
||||||
continue;
|
|
||||||
}
|
/* Compare the part before colon with the target extension name */
|
||||||
*ptr = 0;
|
*ptr = 0;
|
||||||
|
|
||||||
if (strcmp(buf + 5, extEntry->name))
|
if (strcmp(buf + 5, extEntry->name))
|
||||||
continue;
|
goto skip;
|
||||||
|
|
||||||
|
/* Get the opcode for the request, event, or error */
|
||||||
offset = strtol(buf + 1, &ptr, 10);
|
offset = strtol(buf + 1, &ptr, 10);
|
||||||
if (offset == 0 && ptr == buf + 1) {
|
if (offset == 0 && ptr == buf + 1)
|
||||||
LogMessage(X_WARNING, "Invalid line in " FILENAME ", skipping\n");
|
goto invalid;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/* Save the strdup result in the registry */
|
||||||
switch(buf[0]) {
|
switch(buf[0]) {
|
||||||
case PROT_REQUEST:
|
case PROT_REQUEST:
|
||||||
if (extEntry->base)
|
if (extEntry->base)
|
||||||
RegisterRequestName(extEntry->base, offset, lineobj);
|
RegisterRequestName(extEntry->base, offset, lineobj);
|
||||||
else
|
else
|
||||||
RegisterRequestName(offset, 0, lineobj);
|
RegisterRequestName(offset, 0, lineobj);
|
||||||
break;
|
continue;
|
||||||
case PROT_EVENT:
|
case PROT_EVENT:
|
||||||
RegisterEventName(extEntry->eventBase + offset, lineobj);
|
RegisterEventName(extEntry->eventBase + offset, lineobj);
|
||||||
break;
|
continue;
|
||||||
case PROT_ERROR:
|
case PROT_ERROR:
|
||||||
RegisterErrorName(extEntry->errorBase + offset, lineobj);
|
RegisterErrorName(extEntry->errorBase + offset, lineobj);
|
||||||
break;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
invalid:
|
||||||
|
LogMessage(X_WARNING, "Invalid line in " FILENAME ", skipping\n");
|
||||||
|
skip:
|
||||||
|
free(lineobj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue