1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | #include <stdbool.h> |
25 | #include <stdint.h> |
26 | #include <sys/types.h> |
27 | #include <stdlib.h> |
28 | #include <string.h> |
29 | |
30 | #include "utils/errors.h" |
31 | #include "utils/nsurl.h" |
32 | #include "utils/url.h" |
33 | |
34 | #include "content/fetch.h" |
35 | #include "desktop/searchweb.h" |
36 | |
37 | #include "private.h" |
38 | #include "websearch.h" |
39 | |
40 | static nserror |
41 | process_query_section(const char *str, size_t len, char **term) |
42 | { |
43 | if (len < 3) { |
44 | return NSERROR_BAD_PARAMETER; |
45 | } |
46 | if (str[0] != 'q' || str[1] != '=') { |
47 | return NSERROR_BAD_PARAMETER; |
48 | } |
49 | return url_unescape(str + 2, len - 2, NULL, term); |
50 | } |
51 | |
52 | static nserror |
53 | searchterm_from_query(struct nsurl *url, char **term) |
54 | { |
55 | nserror res; |
56 | char *querystr; |
57 | size_t querylen; |
58 | size_t kvstart; |
59 | size_t kvlen; |
60 | |
61 | res = nsurl_get(url, NSURL_QUERY, &querystr, &querylen); |
62 | if (res != NSERROR_OK) { |
| 3 | | Assuming 'res' is equal to NSERROR_OK | |
|
| |
63 | return res; |
64 | } |
65 | |
66 | for (kvlen = 0, kvstart = 0; kvstart < querylen; kvstart += kvlen) { |
| 5 | | Assuming 'kvstart' is >= 'querylen' | |
|
| 6 | | Loop condition is false. Execution continues on line 80 | |
|
67 | |
68 | kvlen = 0; |
69 | while (((kvstart + kvlen) < querylen) && |
70 | (querystr[kvstart + kvlen] != '&')) { |
71 | kvlen++; |
72 | } |
73 | |
74 | res = process_query_section(querystr + kvstart, kvlen, term); |
75 | if (res == NSERROR_OK) { |
76 | break; |
77 | } |
78 | kvlen++; |
79 | } |
80 | free(querystr); |
81 | |
82 | return res; |
| 7 | | Returning without writing to '*term' | |
|
83 | } |
84 | |
85 | bool fetch_about_websearch_handler(struct fetch_about_context *ctx) |
86 | { |
87 | nserror res; |
88 | nsurl *url; |
89 | char *term; |
| 1 | 'term' declared without an initial value | |
|
90 | |
91 | res = searchterm_from_query(fetch_about_get_url(ctx), &term); |
| 2 | | Calling 'searchterm_from_query' | |
|
| 8 | | Returning from 'searchterm_from_query' | |
|
92 | if (res != NSERROR_OK) { |
| |
93 | return false; |
94 | } |
95 | |
96 | res = search_web_omni(term, SEARCH_WEB_OMNI_SEARCHONLY, &url); |
| 10 | | 1st function call argument is an uninitialized value |
|
97 | free(term); |
98 | if (res != NSERROR_OK) { |
99 | return false; |
100 | } |
101 | |
102 | fetch_about_redirect(ctx, nsurl_access(url)); |
103 | nsurl_unref(url); |
104 | |
105 | return true; |
106 | } |