Commit d82353e5 authored by Joe Perches's avatar Joe Perches Committed by Takashi Iwai

ALSA: hda - Fix and neaten print_nid_path/debug_badness

print_nid_path has a possible buffer overflow if
struct nid_path.path values are > 256.

Avoid this and neaten the output to remove the leading ':'

Neaten debug_badness to always verify arguments.
Signed-off-by: default avatarJoe Perches <joe@perches.com>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 2f6ba2b3
...@@ -350,16 +350,16 @@ static void print_nid_path(struct hda_codec *codec, ...@@ -350,16 +350,16 @@ static void print_nid_path(struct hda_codec *codec,
const char *pfx, struct nid_path *path) const char *pfx, struct nid_path *path)
{ {
char buf[40]; char buf[40];
char *pos = buf;
int i; int i;
*pos = 0;
for (i = 0; i < path->depth; i++)
pos += scnprintf(pos, sizeof(buf) - (pos - buf), "%s%02x",
pos != buf ? ":" : "",
path->path[i]);
buf[0] = 0; codec_dbg(codec, "%s path: depth=%d '%s'\n", pfx, path->depth, buf);
for (i = 0; i < path->depth; i++) {
char tmp[4];
sprintf(tmp, ":%02x", path->path[i]);
strlcat(buf, tmp, sizeof(buf));
}
codec_dbg(codec, "%s path: depth=%d %s\n", pfx, path->depth, buf);
} }
/* called recursively */ /* called recursively */
...@@ -1700,9 +1700,11 @@ static int fill_and_eval_dacs(struct hda_codec *codec, ...@@ -1700,9 +1700,11 @@ static int fill_and_eval_dacs(struct hda_codec *codec,
#define DEBUG_BADNESS #define DEBUG_BADNESS
#ifdef DEBUG_BADNESS #ifdef DEBUG_BADNESS
#define debug_badness(fmt, args...) codec_dbg(codec, fmt, ##args) #define debug_badness(fmt, ...) \
codec_dbg(codec, fmt, ##__VA_ARGS__)
#else #else
#define debug_badness(...) #define debug_badness(fmt, ...) \
do { if (0) codec_dbg(codec, fmt, ##__VA_ARGS__); } while (0)
#endif #endif
#ifdef DEBUG_BADNESS #ifdef DEBUG_BADNESS
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment