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 symbol clash after ncurses introduced format attributes. #64

Merged
merged 1 commit into from
Jul 4, 2023

Conversation

kratz00
Copy link
Contributor

@kratz00 kratz00 commented Jun 20, 2023

If MOJOSETUP_GUI_NCURSES is enabled I see the following compile errors:

[  1%] Building C object CMakeFiles/mojosetupgui_ncurses.dir/gui_ncurses.c.o
In file included from /home/kratz00/coding/mojosetup/gui_ncurses.c:14:
/home/kratz00/coding/mojosetup/gui.h:249:21: error: expected ‘)’ before ‘->’ token
  249 | #define format entry->format
      |                     ^~
In file included from /home/kratz00/coding/mojosetup/gui_ncurses.c:32:
/usr/include/curses.h:713:17: error: expected ‘,’ or ‘;’ before ‘)’ token
  713 |                 GCC_PRINTFLIKE(3,4);
      |                 ^~~~~~~~~~~~~~
/home/kratz00/coding/mojosetup/gui.h:249:21: error: expected ‘)’ before ‘->’ token
  249 | #define format entry->format
      |                     ^~
/usr/include/curses.h:715:17: error: expected ‘,’ or ‘;’ before ‘)’ token
  715 |                 GCC_SCANFLIKE(3,4);
      |                 ^~~~~~~~~~~~~
/home/kratz00/coding/mojosetup/gui.h:249:21: error: expected ‘)’ before ‘->’ token
  249 | #define format entry->format
      |                     ^~
/usr/include/curses.h:738:17: error: expected ‘,’ or ‘;’ before ‘)’ token
  738 |                 GCC_PRINTFLIKE(4,5);
      |                 ^~~~~~~~~~~~~~
/home/kratz00/coding/mojosetup/gui.h:249:21: error: expected ‘)’ before ‘->’ token
  249 | #define format entry->format
      |                     ^~
/usr/include/curses.h:740:17: error: expected ‘,’ or ‘;’ before ‘)’ token
  740 |                 GCC_SCANFLIKE(4,5);
      |                 ^~~~~~~~~~~~~
/home/kratz00/coding/mojosetup/gui.h:249:21: error: expected ‘)’ before ‘->’ token
  249 | #define format entry->format
      |                     ^~
/usr/include/curses.h:762:17: error: expected ‘,’ or ‘;’ before ‘)’ token
  762 |                 GCC_PRINTFLIKE(1,2);
      |                 ^~~~~~~~~~~~~~
/home/kratz00/coding/mojosetup/gui.h:249:21: error: expected ‘)’ before ‘->’ token
  249 | #define format entry->format
      |                     ^~
/usr/include/curses.h:774:17: error: expected ‘,’ or ‘;’ before ‘)’ token
  774 |                 GCC_SCANFLIKE(1,2);
      |                 ^~~~~~~~~~~~~
/home/kratz00/coding/mojosetup/gui.h:249:21: error: expected ‘)’ before ‘->’ token
  249 | #define format entry->format
      |                     ^~
/usr/include/curses.h:820:17: error: expected ‘,’ or ‘;’ before ‘)’ token
  820 |                 GCC_PRINTFLIKE(2,0);
      |                 ^~~~~~~~~~~~~~
/home/kratz00/coding/mojosetup/gui.h:249:21: error: expected ‘)’ before ‘->’ token
  249 | #define format entry->format
      |                     ^~
/usr/include/curses.h:822:17: error: expected ‘,’ or ‘;’ before ‘)’ token
  822 |                 GCC_PRINTFLIKE(2,0);
      |                 ^~~~~~~~~~~~~~
/home/kratz00/coding/mojosetup/gui.h:249:21: error: expected ‘)’ before ‘->’ token
  249 | #define format entry->format
      |                     ^~
/usr/include/curses.h:824:17: error: expected ‘,’ or ‘;’ before ‘)’ token
  824 |                 GCC_SCANFLIKE(2,0);
      |                 ^~~~~~~~~~~~~
/home/kratz00/coding/mojosetup/gui.h:249:21: error: expected ‘)’ before ‘->’ token
  249 | #define format entry->format
      |                     ^~
/usr/include/curses.h:826:17: error: expected ‘,’ or ‘;’ before ‘)’ token
  826 |                 GCC_SCANFLIKE(2,0);
      |                 ^~~~~~~~~~~~~
/home/kratz00/coding/mojosetup/gui.h:249:21: error: expected ‘)’ before ‘->’ token
  249 | #define format entry->format
      |                     ^~
/usr/include/curses.h:869:17: error: expected ‘,’ or ‘;’ before ‘)’ token
  869 |                 GCC_PRINTFLIKE(2,3);
      |                 ^~~~~~~~~~~~~~
/home/kratz00/coding/mojosetup/gui.h:249:21: error: expected ‘)’ before ‘->’ token
  249 | #define format entry->format
      |                     ^~
/usr/include/curses.h:873:17: error: expected ‘,’ or ‘;’ before ‘)’ token
  873 |                 GCC_SCANFLIKE(2,3);
      |                 ^~~~~~~~~~~~~
/home/kratz00/coding/mojosetup/gui.h:249:21: error: expected ‘)’ before ‘->’ token
  249 | #define format entry->format
      |                     ^~
/usr/include/curses.h:2047:57: error: expected ‘,’ or ‘;’ before ‘)’ token
 2047 | extern NCURSES_EXPORT(void) _tracef (const char *, ...) GCC_PRINTFLIKE(1,2);
      |                                                         ^~~~~~~~~~~~~~
make[2]: *** [CMakeFiles/mojosetupgui_ncurses.dir/build.make:76: CMakeFiles/mojosetupgui_ncurses.dir/gui_ncurses.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:95: CMakeFiles/mojosetupgui_ncurses.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

@icculus
Copy link
Owner

icculus commented Jun 20, 2023

Mmm, I'd rather workaround this in the ncurses-specific code than touch the whole codebase to rename it to "xformat".

@kratz00
Copy link
Contributor Author

kratz00 commented Jun 21, 2023

Sure, adding a workaround just in gui_ncurses.c will work, could be as easy as adding:

#define __attribute__(p) /* nothing */

as used in the official source https://github.com/mirror/ncurses/blob/master/include/curses.h.in#LL555C1-L555C39

This would of course defeat the purpose of the attribute((format(…))) which is a good way to catch trivial format string vulnerabilities. I do not see a solution which would fulfill both goals - not touching most of the code base and not disabling format string error detection.

@kratz00
Copy link
Contributor Author

kratz00 commented Jun 27, 2023

ping @icculus

Not sure if you saw my last comment, please advice on how to go forward. 😄

@icculus
Copy link
Owner

icculus commented Jun 28, 2023

Let me look more closely at this tonight.

@icculus
Copy link
Owner

icculus commented Jun 29, 2023

I was thinking something more like this...

diff --git a/gui_ncurses.c b/gui_ncurses.c
index a341989..2a01869 100644
--- a/gui_ncurses.c
+++ b/gui_ncurses.c
@@ -19,6 +19,9 @@ MOJOGUI_PLUGIN(ncurses)
 CREATE_MOJOGUI_ENTRY_POINT(ncurses)
 #endif
 
+// ncurses headers use 'format' in an __attribute__, undefine ours for now.
+#undef format
+
 #include <unistd.h>
 #include <ctype.h>
 // CMake searches for a whole bunch of different possible curses includes
@@ -36,6 +39,10 @@ CREATE_MOJOGUI_ENTRY_POINT(ncurses)
 
 #include <locale.h>
 
+// restore the format define from gui.h now that the ncurses headers are done.
+#define format entry->format
+
+
 // This was built to look roughly like dialog(1), but it's not nearly as
 //  robust. Also, I didn't use any of dialog's code, as it is GPL/LGPL,
 //  depending on what version you start with. There _is_ a libdialog, but

The #defines are in gui.h in the first place so you can call these functions in a plugin the same as you can call them in the main program. I think this was probably the right call, but the macro magic is definitely kind of nasty.

@kratz00
Copy link
Contributor Author

kratz00 commented Jul 4, 2023

@icculus thanks, great idea.
I've updated this pull request and attributed you as author (or just close it and push your fix directly 😄).

@icculus icculus merged commit 2dd208e into icculus:main Jul 4, 2023
@kratz00 kratz00 deleted the ncurses_fix branch July 5, 2023 05:08
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