return false;
}
- if (srclen >= SIZE_MAX / 3) {
+ if (srclen >= (SIZE_MAX - 2) / 3) {
DBG_ERR("convert_string_talloc: "
"srclen is %zu, destlen would wrap!\n",
srclen);
errno = EOPNOTSUPP;
return false;
}
- destlen = srclen * 3 / 2;
-
- convert: /* this is a do-while loop with case E2BIG below. */
-
- /* +2 is for ucs2 null termination. */
- if ((destlen*2)+2 <= destlen) {
- /* wrapped ! abort. */
- DEBUG(0, ("convert_string_talloc: destlen wrapped !\n"));
- TALLOC_FREE(outbuf);
- errno = EOPNOTSUPP;
- return false;
- } else {
- destlen = destlen * 2;
- }
+ destlen = srclen * 3;
/* +2 is for ucs2 null termination. */
ob = talloc_realloc(ctx, ob, char, destlen + 2);
DEBUG(3,("convert_string_talloc: Conversion error: %s(%s)\n",reason,inbuf));
break;
case E2BIG:
- goto convert;
+ reason = "output buffer is too small";
+ DBG_NOTICE("convert_string_talloc: "
+ "Conversion error: %s(%s)\n",
+ reason, inbuf);
+ break;
case EILSEQ:
reason="Illegal multibyte sequence";
DEBUG(3,("convert_string_talloc: Conversion error: %s(%s)\n",reason,inbuf));