diff options
author | Eamon Walsh <ewalsh@tycho.nsa.gov> | 2008-06-24 20:32:24 -0400 |
---|---|---|
committer | Eamon Walsh <ewalsh@moss-charon.epoch.ncsc.mil> | 2008-06-24 22:03:30 -0400 |
commit | 5d66908975c6549f459da5bc70358d65c4de76e9 (patch) | |
tree | 526eba7d400512ef0d614affaf29d4b026ae420b /dix | |
parent | 7351c07ae89986bde8053afd8cdcc6a390fd93d5 (diff) |
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)
Diffstat (limited to 'dix')
-rw-r--r-- | dix/registry.c | 44 |
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); } } |