Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix --tab error #5

Closed
wants to merge 3 commits into from
Closed

Conversation

stevenyvr987
Copy link
Contributor

The error occurs when a tab number greater than one is given, which will
cause obconf to crash with a segmentation violation. For example, typing
'obconf --tab 2' on the console will crash insteading of launching a GUI
with tab 2 selected. The error is caused by using the MAX macro with a
first argument that is not an idempotent expression (file main.c, line
number 135):

obc_tab = MAX(atoi(argv[++i]) - 1, 0);

where MAX is defined in file /usr/include/x86_64-linux-gnu/sys/param.h:

#define MAX(a,b) (((a)>(b))?(a):(b))

where the result will be the first argument a if it is more than the
second argument b, otherwise the result will be b, ie, the result will
be the maximum of a or b. Notice that a or b will be evaluated twice,
depending on the > comparison, which means that a and b should always be
idempotent expression, assuming that the compiler does not generate code
to cache a and b values as intermediate results.

In our case, if the argument counter i is zero or one, a will be
evaluated once, but if it is two or more, a will be evaluated twice,
which means that the argv array will be accessed past its natural end.

Martín Aranciaga and others added 3 commits April 26, 2014 00:24
Complete the Spanish (ES) translation
The error occurs when a tab number greater than one is given, which will
cause obconf to crash with a segmentation violation. For example, typing
'obconf --tab 2' on the console will crash insteading of launching a GUI
with tab 2 selected. The error is caused by using the MAX macro with a
first argument that is not an idempotent expression (file main.c, line
number 135):

    obc_tab = MAX(atoi(argv[++i]) - 1, 0);

where MAX is defined in file /usr/include/x86_64-linux-gnu/sys/param.h:

    #define MAX(a,b) (((a)>(b))?(a):(b))

where the result will be the first argument a if it is more than the
second argument b, otherwise the result will be b, ie, the result will
be the maximum of a or b. Notice that a or b will be evaluated twice,
depending on the > comparison, which means that a and b should always be
idempotent expression, assuming that the compiler does not generate code
to cache a and b values as intermediate results.

In our case, if the argument counter i is zero or one, a will be
evaluated once, but if it is two or more, a will be evaluated twice,
which means that the argv array will be accessed past its natural end.
@stevenyvr987
Copy link
Contributor Author

The error is reported many times at launchpad for the Ubuntu distribution; the master ticket is https://bugs.launchpad.net/ubuntu/+source/obconf/+bug/1272834. There, the earliest report is dated 2013 October, https://bugs.launchpad.net/ubuntu/+source/lxpanel/+bug/1236417.
Surprisingly, I cannot find a report of the error at the upstream issue tracker, https://bugzilla.icculus.org/buglist.cgi?quicksearch=obconf.

As a followup, I have inspected all usages of MAX and its complement MIN in the source code for obconf and openbox and do not find a similar example.

@danakj
Copy link
Owner

danakj commented Feb 13, 2015

Thanks, I've merged and pushed it.

@danakj danakj closed this Feb 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants