Skip to content

Commit

Permalink
display: Fix buffer overflow issues in do_labels.c
Browse files Browse the repository at this point in the history
  • Loading branch information
Shubham Vasudeo Desai committed Jul 12, 2024
1 parent d31afbd commit 4cdbcef
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions display/d.labels/do_labels.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ int do_labels(FILE *infile, int do_rotation)
else if (!strncmp(text, "yof", 3))
sscanf(text, "%*s %d", &yoffset);
else if (!strncmp(text, "col", 3)) {
sscanf(text, "%*s %s", buff);
sscanf(text, "%*s %127s", buff);
set_RGBA_from_str(&color, buff);
}
else if (!strncmp(text, "siz", 3))
Expand All @@ -94,15 +94,15 @@ int do_labels(FILE *infile, int do_rotation)
else if (!strncmp(text, "wid", 3))
sscanf(text, "%*s %lf", &width);
else if (!strncmp(text, "bac", 3)) {
sscanf(text, "%*s %s", buff);
sscanf(text, "%*s %127s", buff);
set_RGBA_from_str(&background, buff);
}
else if (!strncmp(text, "bor", 3)) {
sscanf(text, "%*s %s", buff);
sscanf(text, "%*s %127s", buff);
set_RGBA_from_str(&border, buff);
}
else if (!strncmp(text, "opa", 3)) {
sscanf(text, "%*s %s", buff);
sscanf(text, "%*s %127s", buff);
if (!strncmp(buff, "YES", 3))
opaque = YES;
else
Expand All @@ -115,15 +115,15 @@ int do_labels(FILE *infile, int do_rotation)
}
}
else if (!strncmp(text, "fon", 3)) {
if (sscanf(text, "%*s %s", font) != 1 || !strcmp(font, "standard"))
if (sscanf(text, "%*s %255s", font) != 1 || !strcmp(font, "standard"))
strcpy(font, std_font);
}
else if (!strncmp(text, "rot", 3)) {
if (do_rotation)
sscanf(text, "%*s %lf", &rotation);
}
else if (!strncmp(text, "hco", 3)) {
sscanf(text, "%*s %s", buff);
sscanf(text, "%*s %127s", buff);
set_RGBA_from_str(&highlight_color, buff);
}
else if (!strncmp(text, "hwi", 3))
Expand Down Expand Up @@ -452,7 +452,7 @@ int scan_ref(char *buf)
if (buf[i] >= 'A' && buf[i] <= 'Z')
buf[i] += 'a' - 'A';
xref = yref = CENT;
switch (sscanf(buf, "%s%s", word1, word2)) {
switch (sscanf(buf, "%49s%49s", word1, word2)) {

Check failure

Code scanning / CodeQL

Incorrect return-value check for a 'scanf'-like function High

The result of scanf is only checked against 0, but it can also return EOF.
case 2:
if (!(xmatch(word2) || ymatch(word2)))
return 0;
Expand Down

0 comments on commit 4cdbcef

Please sign in to comment.