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 false positives of IS_*() macros for 8-bit ASCII characters #5844

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 17 additions & 12 deletions crypto/conf/conf_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,26 @@
#define KEYTYPES(c) ((const unsigned short *)((c)->meth_data))

#ifndef CHARSET_EBCDIC
# define CVT(a) ((a) & 0x7F)
# define CVT(a) ((unsigned char)(a) <= 127 ? (unsigned char)(a) : 127)
#else
# define CVT(a) os_toascci[(a) & 0x7F]
# define CVT(a) os_toascii[(unsigned char)(a)]
#endif

#define IS_COMMENT(c,a) (KEYTYPES(c)[CVT(a)] & CONF_COMMENT)
#define IS_FCOMMENT(c,a) (KEYTYPES(c)[CVT(a)] & CONF_FCOMMENT)
#define IS_EOF(c,a) (KEYTYPES(c)[CVT(a)] & CONF_EOF)
#define IS_ESC(c,a) (KEYTYPES(c)[CVT(a)] & CONF_ESC)
#define IS_NUMBER(c,a) (KEYTYPES(c)[CVT(a)] & CONF_NUMBER)
#define IS_WS(c,a) (KEYTYPES(c)[CVT(a)] & CONF_WS)
#define IS_ALNUM(c,a) (KEYTYPES(c)[CVT(a)] & CONF_ALNUM)
#define IS_ALNUM_PUNCT(c,a) (KEYTYPES(c)[CVT(a)] & CONF_ALNUM_PUNCT)
#define IS_QUOTE(c,a) (KEYTYPES(c)[CVT(a)] & CONF_QUOTE)
#define IS_DQUOTE(c,a) (KEYTYPES(c)[CVT(a)] & CONF_DQUOTE)
/*
* Attention: because the macro argument 'a' is evaluated twice in CVT(a),
* it is not allowed pass 'a' arguments with side effects to IS_*(c,a)
* like for example IS_*(c, *p++).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, but I think that introducing this kind of fragility is the wrong way to go.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But note that this header file is used/included in only one internal source file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we only shoot our own kneecaps off... still.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're stuck with moving forward in pieces, I guess, because we had to remove the previous code.

*/
#define IS_COMMENT(c,a) ((KEYTYPES(c)[CVT(a)] & CONF_COMMENT) ? 1 : 0)
#define IS_FCOMMENT(c,a) ((KEYTYPES(c)[CVT(a)] & CONF_FCOMMENT) ? 1 : 0)
#define IS_EOF(c,a) ((KEYTYPES(c)[CVT(a)] & CONF_EOF) ? 1 : 0)
#define IS_ESC(c,a) ((KEYTYPES(c)[CVT(a)] & CONF_ESC) ? 1 : 0)
#define IS_NUMBER(c,a) ((KEYTYPES(c)[CVT(a)] & CONF_NUMBER) ? 1 : 0)
#define IS_WS(c,a) ((KEYTYPES(c)[CVT(a)] & CONF_WS) ? 1 : 0)
#define IS_ALNUM(c,a) ((KEYTYPES(c)[CVT(a)] & CONF_ALNUM) ? 1 : 0)
#define IS_ALNUM_PUNCT(c,a) ((KEYTYPES(c)[CVT(a)] & CONF_ALNUM_PUNCT) ? 1 : 0)
#define IS_QUOTE(c,a) ((KEYTYPES(c)[CVT(a)] & CONF_QUOTE) ? 1 : 0)
#define IS_DQUOTE(c,a) ((KEYTYPES(c)[CVT(a)] & CONF_DQUOTE) ? 1 : 0)

static const unsigned short CONF_type_default[128] = {
0x0008, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
Expand Down
29 changes: 17 additions & 12 deletions crypto/conf/keysets.pl
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,26 @@
#define KEYTYPES(c) ((const unsigned short *)((c)->meth_data))

#ifndef CHARSET_EBCDIC
# define CVT(a) ((a) & 0x7F)
# define CVT(a) ((unsigned char)(a) <= 127 ? (unsigned char)(a) : 127)
#else
# define CVT(a) os_toascci[(a) & 0x7F]
# define CVT(a) os_toascii[(unsigned char)(a)]
#endif

#define IS_COMMENT(c,a) (KEYTYPES(c)[CVT(a)] & CONF_COMMENT)
#define IS_FCOMMENT(c,a) (KEYTYPES(c)[CVT(a)] & CONF_FCOMMENT)
#define IS_EOF(c,a) (KEYTYPES(c)[CVT(a)] & CONF_EOF)
#define IS_ESC(c,a) (KEYTYPES(c)[CVT(a)] & CONF_ESC)
#define IS_NUMBER(c,a) (KEYTYPES(c)[CVT(a)] & CONF_NUMBER)
#define IS_WS(c,a) (KEYTYPES(c)[CVT(a)] & CONF_WS)
#define IS_ALNUM(c,a) (KEYTYPES(c)[CVT(a)] & CONF_ALNUM)
#define IS_ALNUM_PUNCT(c,a) (KEYTYPES(c)[CVT(a)] & CONF_ALNUM_PUNCT)
#define IS_QUOTE(c,a) (KEYTYPES(c)[CVT(a)] & CONF_QUOTE)
#define IS_DQUOTE(c,a) (KEYTYPES(c)[CVT(a)] & CONF_DQUOTE)
/*
* Attention: because the macro argument 'a' is evaluated twice in CVT(a),
* it is not allowed pass 'a' arguments with side effects to IS_*(c,a)
* like for example IS_*(c, *p++).
*/
#define IS_COMMENT(c,a) ((KEYTYPES(c)[CVT(a)] & CONF_COMMENT) ? 1 : 0)
#define IS_FCOMMENT(c,a) ((KEYTYPES(c)[CVT(a)] & CONF_FCOMMENT) ? 1 : 0)
#define IS_EOF(c,a) ((KEYTYPES(c)[CVT(a)] & CONF_EOF) ? 1 : 0)
#define IS_ESC(c,a) ((KEYTYPES(c)[CVT(a)] & CONF_ESC) ? 1 : 0)
#define IS_NUMBER(c,a) ((KEYTYPES(c)[CVT(a)] & CONF_NUMBER) ? 1 : 0)
#define IS_WS(c,a) ((KEYTYPES(c)[CVT(a)] & CONF_WS) ? 1 : 0)
#define IS_ALNUM(c,a) ((KEYTYPES(c)[CVT(a)] & CONF_ALNUM) ? 1 : 0)
#define IS_ALNUM_PUNCT(c,a) ((KEYTYPES(c)[CVT(a)] & CONF_ALNUM_PUNCT) ? 1 : 0)
#define IS_QUOTE(c,a) ((KEYTYPES(c)[CVT(a)] & CONF_QUOTE) ? 1 : 0)
#define IS_DQUOTE(c,a) ((KEYTYPES(c)[CVT(a)] & CONF_DQUOTE) ? 1 : 0)

EOF

Expand Down