diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2011-01-04 10:00:01 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2011-01-04 10:00:01 +0000 |
commit | bdfc52b61054950405665e0445d8c914b9a2afc7 (patch) | |
tree | 9f62ee1e2dc002d6aa0cafc6335860ea5cb0e5de | |
parent | e7ccdaf6f585e63cab6ec5647f2f0d41e4f1d26e (diff) |
When translating a PDU to text strip all trailing \0 but one.
Fixes parsing of login responses that had additional padding.
-rw-r--r-- | usr.sbin/iscsid/pdu.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/usr.sbin/iscsid/pdu.c b/usr.sbin/iscsid/pdu.c index 7ddfe10008d..dbbc87b0258 100644 --- a/usr.sbin/iscsid/pdu.c +++ b/usr.sbin/iscsid/pdu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pdu.c,v 1.2 2010/09/25 16:20:06 sobrado Exp $ */ +/* $OpenBSD: pdu.c,v 1.3 2011/01/04 10:00:00 claudio Exp $ */ /* * Copyright (c) 2009 Claudio Jeker <claudio@openbsd.org> @@ -91,10 +91,15 @@ pdu_to_text(char *buf, size_t len) char *eq; unsigned int nkvp = 0, i; - if (buf[len - 1]) { + /* remove padding zeros */ + for (n = len; buf[n - 1] == '\0'; n--) + ; + if (n == len) { log_debug("pdu_to_text: badly terminated text data"); return NULL; } + len = n + 1; + for(n = 0; n < len; n++) if (buf[n] == '\0') nkvp++; |