patchlwIP - A Lightweight TCP/IP stack - Patches: patch #9041, ipaddr_aton: Accept URI-style...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

patch #9041: ipaddr_aton: Accept URI-style termination

Submitter:  chrysn <chrysn>
Submitted:  Wed 06 Jul 2016 08:32:02 AM UTC
   
 
Category:  None Priority:  5 - Normal
Status:  Done Privacy:  Public
Assigned to:  None Open/Closed:  Closed
Planned Release:  None

Jump to the original submission

Thu 25 Aug 2016 10:52:22 AM UTC, comment #7: 

Closing this one to clean up patch list. Please reopen this one or create a new patch entry when you are done.

Dirk Ziegelmeier <dziegel>
Group administrator
Tue 19 Jul 2016 06:46:03 PM UTC, comment #6: 

I guess additional functions with explicit length would be OK if it's implementable in a way that prevents code duplication while not having an impact to the standard version (regarding code size and speed).

If that's not possible, just try to temporarily zero-terminate the string and restore the original char after ipaddr_aton() returns.

Simon Goldschmidt <goldsimon>
Group administrator
Wed 06 Jul 2016 12:13:52 PM UTC, comment #5: 

Alright, if this is used to validate input and the whitespace acceptance is part of the spec, the behavior I'd like to see is obviously not that easy to enable.

To explore other ways in which I could parse a URI into an address structure without copying data around: Would an additional function family (6/4/any) like ipaddr_aton be welcome in lwIP that would accept a string with explicit length? Or would that be too niche, and I should rather copy around (either addresses in memory to terminte them, or code to have a custom ipaddr_aton) for libcoap?

chrysn <chrysn>
Wed 06 Jul 2016 11:55:19 AM UTC, comment #4: 

On a side note, "192.168.0.1   " works with inet_aton() but "   192.168.0.1   " doesn't.

It means the current lwIP implementation follows strictly what inet_aton() is doing.

Sylvain Rochet <gradator>
Group Member
Wed 06 Jul 2016 11:49:28 AM UTC, comment #3: 

verbatim+

It doesn't work.

#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>


int main() {
        struct in_addr inaddr;
        printf("%d\n", inet_aton("192.168.0.1/index.html", &inaddr));
        printf("%.8x\n", inaddr.s_addr);
        printf("%d\n", inet_aton("192.168.0.1", &inaddr));
        printf("%.8x\n", inaddr.s_addr);
}


returns:

$ gcc -o test test.c && ./test
0
7619a7d0
1
0100a8c0



inet_aton() returns 1 if the supplied string was successfully interpreted, or 0 if the string is invalid (errno is not set on error).


inet_aton() might be already used in the wild to check user input, therefore the patch is probably not acceptable.


-verbatim-

Sylvain Rochet <gradator>
Group Member
Wed 06 Jul 2016 11:44:00 AM UTC, comment #2: 

Sorry, missed the file upload.

I didn't look specifically into inet_aton, but that appears to be only a macro to ip4addr_aton anyway and should just inherit the behavior. (lwIP's inet_aton & co might then be more permissive than other systems' inet_aton implementations, but would stilll reject most garbage).

(file #37732)

chrysn <chrysn>
Wed 06 Jul 2016 11:35:39 AM UTC, comment #1: 

Where's the patch?
How does this match to inet_addr()/inet_aton() (which is directly mapped to the ip_*() function)?

Simon Goldschmidt <goldsimon>
Group administrator
Wed 06 Jul 2016 08:32:02 AM UTC, original submission:  

ipaddr_aton already accepted whitespace instead of 0 at the end of the address string. The range of acceptable termination characters is now extended (both for V4 and V6 addresses) to include characters to be expected when the address is part of a URI.

This is particularly handy when URIs come along as const char (be it in ROM or in packages) and get parsed in-place, and spares keeping a 40 byte buffer around just to 0-terminate the address strings.

chrysn <chrysn>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by dziegel (Posted a comment)
  • -email is unavailable- added by gradator (Posted a comment)
  • -email is unavailable- added by goldsimon (Posted a comment)
  • -email is unavailable- added by chrysn (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-08-25 dziegel StatusNone Done
        Open/ClosedOpen Closed
    2016-07-06 chrysn Attached File- Added 0001-ipaddr_aton-Accept-URI-style-termination.patch, #37732

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code