Skip to content

Commit 6eba4c0

Browse files
committed
cgi: Fix showing query string in Help
If a string was searched on CUPS Web UI help page, garbage was printed out in search box. It was because text field pointer was freed before and contained garbage - previously it was variable value which was allocated, so the string survived `cgCleanVariables(()`, but the text field is a pointer into form variables which gets cleaned up. Fix is to use `strdup()` if `cgiGetTextfield()` returns non-NULL pointer. The binary exits shortly after either way, so memory is taken care of by OS.
1 parent 0d8542c commit 6eba4c0

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

CHANGES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ Changes in CUPS v2.4.9 (TBA)
1212
(Issue #751)...
1313
- Fixed `Host` header regression (Issue #967)
1414
- Fixed DNS-SD lookups of local services with Avahi (Issue #970)
15-
- Fixed listing jobs in destinations in web ui.
15+
- Fixed listing jobs in destinations in web ui. (Apple issue #6204)
16+
- Fixed showing search query in web ui help page. (Issue #977)
1617

1718

1819
Changes in CUPS v2.4.8 (2024-04-26)

cgi-bin/help.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ main(int argc, /* I - Number of command-line arguments */
2828
*si; /* Search index */
2929
help_node_t *n; /* Current help node */
3030
int i; /* Looping var */
31-
const char *query; /* Search query */
31+
const char *query = NULL; /* Search query */
3232
const char *cache_dir; /* CUPS_CACHEDIR environment variable */
3333
const char *docroot; /* CUPS_DOCROOT environment variable */
3434
const char *helpfile, /* Current help file */
@@ -172,8 +172,9 @@ main(int argc, /* I - Number of command-line arguments */
172172

173173
if (cgiGetVariable("CLEAR"))
174174
cgiSetVariable("QUERY", "");
175+
else if ((query = cgiGetTextfield("QUERY")) != NULL)
176+
query = strdup(query);
175177

176-
query = cgiGetTextfield("QUERY");
177178
si = helpSearchIndex(hi, query, topic, helpfile);
178179

179180
cgiClearVariables();

0 commit comments

Comments
 (0)