summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre Crépieux <pierre.crepieux@orange.com>2012-05-04 16:12:17 +0200
committerPierre Crépieux <pierre.crepieux@orange.com>2012-05-31 18:26:24 +0200
commit00b7b3528890a27c04b2a6da87b790151cea8721 (patch)
tree00f9ea5f3d20a0e7cfb5cdb3f44291a2ee707758
parentf621afad94df46204c25fc2593a19d704d2637f5 (diff)
downloadandroid_external_dnsmasq-00b7b3528890a27c04b2a6da87b790151cea8721.tar.gz
android_external_dnsmasq-00b7b3528890a27c04b2a6da87b790151cea8721.tar.bz2
android_external_dnsmasq-00b7b3528890a27c04b2a6da87b790151cea8721.zip
Ensure all commands read on dnsmasq's stdin are processed
As described in issue 30016, android dnsmasq daemon is misconfigured after initializing tethering. The reason is that two commands are present on dnsmasq stdin when check_android_listeners is called: update_dns:8.8.8.8:8.8.4.4\0update_dns:192.x.y.z (notice the \0 between the 2 commands). check_android_listeners assumes there is a single NUL terminated string and skip the second one. This patch ensure that every commands are processed by checking wether or not all the characters on stdin have been consumed and loop if needed. Also fixes style issues. Change-Id: I6d98233964559b8dcc1253aec105a240e1065c94 Signed-off-by: Pierre Crépieux <pierre.crepieux@orange.com>
-rwxr-xr-xsrc/dnsmasq.c38
1 files changed, 23 insertions, 15 deletions
diff --git a/src/dnsmasq.c b/src/dnsmasq.c
index 1a9d808..f6b371a 100755
--- a/src/dnsmasq.c
+++ b/src/dnsmasq.c
@@ -984,32 +984,40 @@ static int set_android_listeners(fd_set *set, int *maxfdp) {
}
static int check_android_listeners(fd_set *set) {
+ int retcode = 0;
if (FD_ISSET(STDIN_FILENO, set)) {
char buffer[1024];
int rc;
+ int consumed = 0;
if ((rc = read(STDIN_FILENO, buffer, sizeof(buffer) -1)) < 0) {
my_syslog(LOG_ERR, _("Error reading from stdin (%s)"), strerror(errno));
return -1;
}
buffer[rc] = '\0';
- char *next = buffer;
- char *cmd;
-
- if (!(cmd = strsep(&next, ":"))) {
- my_syslog(LOG_ERR, _("Malformatted msg '%s'"), buffer);
- return -1;
- }
-
- if (!strcmp(buffer, "update_dns")) {
- set_servers(&buffer[11]);
- check_servers();
- } else {
- my_syslog(LOG_ERR, _("Unknown cmd '%s'"), cmd);
- return -1;
+ while(consumed < rc) {
+ char *cmd;
+ char *current_cmd = &buffer[consumed];
+ char *params = current_cmd;
+ int len = strlen(current_cmd);
+
+ cmd = strsep(&params, ":");
+ if (!strcmp(cmd, "update_dns")) {
+ if (params != NULL) {
+ set_servers(params);
+ check_servers();
+ } else {
+ my_syslog(LOG_ERR, _("Malformatted msg '%s'"), current_cmd);
+ retcode = -1;
+ }
+ } else {
+ my_syslog(LOG_ERR, _("Unknown cmd '%s'"), cmd);
+ retcode = -1;
+ }
+ consumed += len + 1;
}
}
- return 0;
+ return retcode;
}
#endif