public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "raji at linux dot vnet.ibm.com" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sourceware.org
Subject: [Bug localedata/17596] New: mblen() does not return -1 for invalid input
Date: Thu, 13 Nov 2014 09:49:00 -0000	[thread overview]
Message-ID: <bug-17596-131@http.sourceware.org/bugzilla/> (raw)

https://sourceware.org/bugzilla/show_bug.cgi?id=17596

            Bug ID: 17596
           Summary: mblen() does not return -1 for invalid input
           Product: glibc
           Version: 2.21
            Status: NEW
          Severity: minor
          Priority: P2
         Component: localedata
          Assignee: unassigned at sourceware dot org
          Reporter: raji at linux dot vnet.ibm.com
                CC: libc-locales at sourceware dot org

The standard document for mblen() states:

#include <stdlib.h>
int mblen(const char *s, size_t n);

The standard states:
"If s is a null pointer, the mblen function returns a nonzero or zero value, if
multibyte character encodings, respectively,
 do or do not have state-dependent encodings. If s is not a null pointer, the
mblen function either returns 0
(if s points to the null character), or returns the number of bytes that are
contained in the multibyte character
(if the next n or fewer bytes form a valid multibyte character), or returns -1
(if they do not form a valid multibyte character). "


The case n=0 is not explicitly mentioned in the standards document and is also
not handled in the code(stdlib/mblen.c)
When compiled on AIX (v6.1 and other releases) mblen() returns -1.

$ cat mblen_t.c
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>

main() {
     char sbcs_st[]  = "12345";

     if ( setlocale( LC_ALL, "" ) == NULL ) {
        printf( "setlocale() failed\n" );
     }
     printf("RC is %d\n", mblen(sbcs_st, 0));
}

$ gcc -o mblen_t mblen_t.c;./mblen_t
RC is 0


https://sourceware.org/ml/libc-alpha/2014-11/msg00191.html

-- 
You are receiving this mail because:
You are on the CC list for the bug.


             reply	other threads:[~2014-11-13  9:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-13  9:49 raji at linux dot vnet.ibm.com [this message]
2014-11-13  9:50 ` [Bug localedata/17596] " raji at linux dot vnet.ibm.com
2014-11-20 17:10 ` raji at linux dot vnet.ibm.com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-17596-131@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).