xserver: Branch 'server-1.5-branch'
Eamon Walsh
ewalsh at kemper.freedesktop.org
Tue Jun 24 19:09:25 PDT 2008
dix/registry.c | 44 ++++++++++++++++++++++++++------------------
1 file changed, 26 insertions(+), 18 deletions(-)
New commits:
commit 5d66908975c6549f459da5bc70358d65c4de76e9
Author: Eamon Walsh <ewalsh at tycho.nsa.gov>
Date: Tue Jun 24 20:32:24 2008 -0400
Fix a leak in the code that parses the protocol names.
Also added some comments.
Reported by Ben Gamari (bug #16492).
(cherry picked from commit a3ec22627355fc08730ad7e90022e374763d333f)
diff --git a/dix/registry.c b/dix/registry.c
index 10fa21f..a519cff 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);
}
}
More information about the xorg-commit
mailing list