Re: Potential Patch for consolekit?
Hello,
Barry deFreese, le Sat 23 May 2009 00:01:17 -0400, a écrit :
> @@ -235,7 +235,7 @@
> const char *s;
> uid_t uid;
> char buf[256];
> - char ttybuf[PATH_MAX];
> + char *ttybuf;
> DBusError error;
> dbus_bool_t is_local;
>
> @@ -286,8 +286,14 @@
> x11_display = display_device;
> display_device = "";
> } else if (strncmp (_PATH_DEV, display_device, 5) != 0) {
> + int tmp_buf = strlen(_PATH_DEV) + strlen(display_device) + 1;
> + if (( ttybuf = malloc(tmp_buf) ) == NULL ) {
> + printf("Unable to allocate TTY buffer\n");
> + goto out;
> + }
> snprintf (ttybuf, sizeof (ttybuf), _PATH_DEV "%s", display_device);
> display_device = ttybuf;
> + free(ttybuf);
> }
You can also move the ttybuf declaration inside the if branch, so that
you can keep it as an array, whose size will be
strlen(_PATH_DEV) + strlen(display_device) + 1;
That will fix the now-erroneous sizeof(ttybuf) (when ttybuf is a
pointer, that would return the size of the pointer, not the size of what
is allocated).
> +/* adapted from procps */
> +/* Load /proc/tty/drivers for device name mapping use. */
We don't have that, and I don't think we should have it anyway, so you
can drop that part of the code.
Samuel
Reply to: