summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEamon Walsh <ewalsh@tycho.nsa.gov>2008-06-24 20:32:24 -0400
committerEamon Walsh <ewalsh@moss-charon.epoch.ncsc.mil>2008-06-24 22:00:55 -0400
commita3ec22627355fc08730ad7e90022e374763d333f (patch)
tree53c2a279170d0a6584e9163bfd415ab0231ba861
parenta4cb25f8c816adc3bdf6a28d5beb558e8be40121 (diff)
Fix a leak in the code that parses the protocol names.
Also added some comments. Reported by Ben Gamari (bug #16492).
-rw-r--r--dix/registry.c44
1 files changed, 26 insertions, 18 deletions
diff --git a/dix/registry.c b/dix/registry.c
index 10fa21f84..a519cff6b 100644
--- a/dix/registry.c
+++ b/dix/registry.c
@@ -126,10 +126,12 @@ RegisterExtensionNames(ExtensionEntry *extEntry)
rewind(fh);
while (fgets(buf, sizeof(buf), fh)) {
+ lineobj = NULL;
ptr = strchr(buf, '\n');
if (ptr)
*ptr = 0;
+ /* Check for comments or empty lines */
switch (buf[0]) {
case PROT_REQUEST:
case PROT_EVENT:
@@ -139,48 +141,54 @@ RegisterExtensionNames(ExtensionEntry *extEntry)
case '\0':
continue;
default:
- continue;
+ goto invalid;
}
+ /* Check for space character in the fifth position */
ptr = strchr(buf, ' ');
- if (!ptr || ptr != buf + 4) {
- LogMessage(X_WARNING, "Invalid line in " FILENAME ", skipping\n");
- continue;
- }
+ if (!ptr || ptr != buf + 4)
+ goto invalid;
+
+ /* Duplicate the string after the space */
lineobj = strdup(ptr + 1);
if (!lineobj)
continue;
+ /* Check for a colon somewhere on the line */
ptr = strchr(buf, ':');
- if (!ptr) {
- LogMessage(X_WARNING, "Invalid line in " FILENAME ", skipping\n");
- continue;
- }
- *ptr = 0;
+ if (!ptr)
+ goto invalid;
+ /* Compare the part before colon with the target extension name */
+ *ptr = 0;
if (strcmp(buf + 5, extEntry->name))
- continue;
+ goto skip;
+ /* Get the opcode for the request, event, or error */
offset = strtol(buf + 1, &ptr, 10);
- if (offset == 0 && ptr == buf + 1) {
- LogMessage(X_WARNING, "Invalid line in " FILENAME ", skipping\n");
- continue;
- }
+ if (offset == 0 && ptr == buf + 1)
+ goto invalid;
+ /* Save the strdup result in the registry */
switch(buf[0]) {
case PROT_REQUEST:
if (extEntry->base)
RegisterRequestName(extEntry->base, offset, lineobj);
else
RegisterRequestName(offset, 0, lineobj);
- break;
+ continue;
case PROT_EVENT:
RegisterEventName(extEntry->eventBase + offset, lineobj);
- break;
+ continue;
case PROT_ERROR:
RegisterErrorName(extEntry->errorBase + offset, lineobj);
- break;
+ continue;
}
+
+ invalid:
+ LogMessage(X_WARNING, "Invalid line in " FILENAME ", skipping\n");
+ skip:
+ free(lineobj);
}
}